使用逗号以货币读取txt文件

时间:2016-05-23 07:24:29

标签: csv sas

如何用货币逗号读取txt文件?

  

123," Harold Wilson",Acct,01/15/1989,$ 78,123。

     

128," Julia Child",Food,08/29/1988

     007,"詹姆斯邦德",安全,02/01/2000,$ 82,100

这是我的尝试:

data employee;
    infile file dsd;
    input 
        id : $3. 
        name : $20. 
        xxx : $ 
        date : mmddyy8.
        cash : dollar8.;
    format 
        date date9.
        cash dollar8.;
run;

proc print data=employee;
run;

2 个答案:

答案 0 :(得分:2)

由于问题字段是最后一个,你只需更改分隔符,也需要MISSOVER。

filename FT15F001 temp;
data employee;
   infile FT15F001 dsd dlm=dlm missover;
      dlm=','; input id:$3. name:$20. xxx:$ date:mmddyy8. @;
      dlm='|'; input  cash:dollar8.;
      format date date9. cash dollar8.;
   parmcards;
123,"Harold Wilson",Acct,01/15/1989,$78,123.
128,"Julia Child",Food,08/29/1988
007,"James Bond",Security,02/01/2000,$82,100
;;;;
   run;

答案 1 :(得分:1)

使用comma.信息并将分隔符更改为;(或,以外的任何内容)可能是明智的选择......

如果你不能,这是一个解决方法:

data employee;

  infile datalines dsd truncover;

  informat id $3.
           name $QUOTE20.
           xxx $12.
           date mmddyy10.
           cash1 $6.
           cash2 $6.;

    format date date9.
           cash dollar11.2;

    input id name xxx date cash1 cash2;

    cash = input(cats(cash1, cash2), comma10.);

    drop cash1 cash2;

  datalines;
123,"Harold Wilson",Acct,01/15/1989,$78,123.
128,"Julia Child",Food,08/29/1988
007,"James Bond",Security,02/01/2000,$82,100
;

结果

id   name           xxx            date        cash
---  -------------  --------  ---------  ----------
123  Harold Wilson  Acct      15JAN1989  $78,123.00 
128  Julia Child    Food      29AUG1988  . 
007  James Bond     Security  01FEB2000  $82,100.00