【问题标题】:Add apostrophe in front of a number in sas在sas中的数字前面添加撇号
【发布时间】:2019-07-19 18:01:14
【问题描述】:

我想在变量前添加撇号 - sas 中的数字,以便 excel 中的输出显示为正确的数字而不是科学计数法

proc SQL; 创建表PERM.accounts为 选择不同的 input(LOAN_ACCOUNT_NO, $30.) as 'Account No'n 但这会在 excel 中产生类似这样的数字:1.23456E+12 - 但我需要输出如下所示:1234567891234 欺骗excel的方法是在数字前面加上一个撇号,例如:'1234567891234 如何在 proc sql 中编码?

 ,input(LOAN_ACCOUNT_NO, best32.)   as 'Account No'n
,input(LOAN_ACCOUNT_NO, $30.)   as 'Account No'n

如何在 proc sql 函数中使用 catx 语句附加 LOAN_ACCOUNT_NO?

更多代码(来自评论)

%SASSTARTUP; 
%macro EXPORT_MAIL (
  IN_DSNAME=PERM.FINAL_&END_CURR_MTH,
  CSV_FNAME=DATA_&END_CURR_MTH
);
  proc EXPORT 
    data=&IN_DSNAME 
    outfile="&OUTPUT_DATA_DIR.\&CSV_FNAME..csv" 
    dbms=CSV 
    replace label;
  run;
  filename myfile EMAIL 
    to=("&EMAIL_RECIP_1.") 
    from=(‘ @ ‘) 
    replyto=(‘ @ ‘)
    subject=("Sample")
    attach=(
      "&OUTPUT_DATA_DIR.\&CSV_FNAME..csv"
      content_type='application/excel'
    )
  ;

  data NULL; 
    file myfile; 
    put ' '; 
    put "The latest Sample is attached."; 
    put ' ';
  run;
%mend EXPORT_MAIL;

【问题讨论】:

  • 来源中贷款账号的数据类型是什么?
  • 它是一个字符变量
  • 我现在试过了: ,catx( "'" , LOAN_ACCOUNT_NO ) as 'Account No'n 这适用于 SAS 但 excel 将其恢复为科学记数法
  • 你能说明你是如何将文件导出到 excel 中的吗?
  • %SASSTARTUP; %macro EXPORT_MAIL (IN_DSNAME=PERM.FINAL_&END_CURR_MTH, CSV_FNAME=DATA_&END_CURR_MTH); proc EXPORT data=&IN_DSNAME outfile="&OUTPUT_DATA_DIR.\&CSV_FNAME..csv" dbms=CSV 替换标签;跑;文件名 myfile EMAIL to=("&EMAIL_RECIP_1." ) from=('@') replyto=('@')) subject=("Sample") attach=("&OUTPUT_DATA_DIR.\&CSV_FNAME..csv" content_type='application/优秀'); ; ...

标签: sas


【解决方案1】:

在创建要使用 Excel 打开的 csv 附件时,问题更多的是"Long number in CSV file appearing in scientific notation by default",它表示在 csv 的默认打开操作期间,Excel 将遵循 csv 中的文本公式。

您还可以通过将硬空格字符 (xA0) 附加到帐号来强制 SAS Proc Export 输出双引号字符值。

例子:

data have;
  acct = '123456789012345';
  accnum = input(acct,best32.);
  acctsq = cats("'",acct);

  acctweak = strip(acct)||byte(160);
  acctdqformula = cats('=TEXT(',acct,',"0")');
run;

proc export data=have outfile="c:\temp\sandbox.csv" dbms=csv replace label;
run;

options noxwait noxsync xmin;
%sysexec start "Open Excel" excel c:\temp\sandbox.csv;

所以你创建PERM.FINAL_&END_CURR_MTH的SQL语句可以有

, strip(LOAN_ACCOUNT_NO)||byte(160) as 'Account No'n
, cats('=TEXT(',LOAN_ACCOUNT_NO,',"0")') as 'Account No'n

为附件创建一个 Excel 文件

ODS EXCEL file = "&OUTPUT_DATA_DIR.\&CSV_FNAME..xlsx";
proc PRINT data=&IN_DSNAME;
ODS EXCEL CLOSE;

… attach &CSV_FNAME..xlsx with content type application/ms-excel

【讨论】:

    【解决方案2】:

    尝试 ODS 而不是 PROC EXPORT:

    ODS tagsets.ExcelXP FILE = "DATA_&END_CURR_MTH..xml";
    
    proc print data=PERM.FINAL_&END_CURR_MTH;
      format .....;
    run;
    

    在打印语句中适当地设置格式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-20
      • 2017-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多