全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2375 11
2009-08-27
数据显然是四列,名字是一列 带空格 需要整体导入 不要拆开的,谢谢关注

这个参考有错误
data example;
infile 'c:\x.txt'  ;
input Subj  : $3.  Name & $20.  DOB : mmddyy10. Salary  : dollar8.;
format DOB date9. Salary dollar8.;
run;


/*下面数据存到C盘 起名 x.txt  
001 Christopher Mullens 11/12/1955 $45,200
002 Michelle   Kwo 9/12/1955 $78,123
003 Roger W. McDonald 1/1/1960 $107,200
*/
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2009-8-27 08:34:44
002 Michelle   Kwo  9/12/1955 $78,123
是不是这一行'Michelle' 和'Kwo'之间多了一个空格(delimiter)?
用&的话,'Michelle' 和'Kwo' 之间只能有一个空格,而'Kwo'之后要有两个以上空格。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2009-8-27 10:46:34
pobel 发表于 2009-8-27 08:34
002 Michelle   Kwo  9/12/1955 $78,123
是不是这一行'Michelle' 和'Kwo'之间多了一个空格(delimiter)?
用&的话,'Michelle' 和'Kwo' 之间只能有一个空格,而'Kwo'之后要有两个以上空格。
牛 把kwo改成2个空格果然成功了 但如果真是一个空格的话,该如何处理呢?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2009-8-27 11:04:40
用&修饰字符变量,比如name一类的,与后面的变量至少又有两个空格,向前进一个,实际上就达到了两个空格的效果
下面是sas帮助文档中的举例说明
data list;
   infile file-specification;
   input name $ & score;
run;
It can read these input data records:

----+----1----+----2----+----3----+
Joseph   11 Joergensen  red
Mitchel  13 Mc Allister  blue
Su Ellen  14 Fischer-Simon  green
The & modifier follows the variable it affects in the INPUT statement. Because this format modifier follows NAME, at least two blanks must separate the NAME field from the SCORE field in the input data records.

You can also specify an informat with a format modifier, as shown here:
    input name $ & +3 lastname & $15. team $;In addition, this INPUT statement reads the same data to demonstrate that you are not required to read all the values in an input record. The +3 column pointer control moves the pointer past the score value in order to read the value for LASTNAME and TEAM.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2009-8-27 11:17:28
data example(drop=temp);                                                                                                               
length temp $20.;                                                                                                               
input Subj  : $3.  Name: & $20. temp $ @;                                                                                       
if index(temp,'/')>0 then input   Salary  : dollar8.;                                                                           
else do;                                                                                                                        
Name=trim(Name)||' '||temp;                                                                                             
        input temp $  Salary  : dollar8.;                                                                                       
end;                                                                                                                           
DOB=input(temp,mmddyy10.);                        
format DOB date9. Salary dollar8.;                                                                                             
datalines;                                                                                                                              
001 Christopher Mullens  11/12/1955 $45,200                                                                                             
002 Michelle   Kwo  9/12/1955 $78,123                                                                                                   
003 Roger W. McDonald  1/1/1960 $107,200                                                                                                
;                                                                                                                                       
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2009-8-27 11:20:59
本例中,如果名字可能含两个空格的话:
data example(drop=temp);                                                                                                               
length temp $20.;                                                                                                               
input Subj  : $3.  Name: & $20. temp $ @;                                                                                       
if index(temp,'/')>0 then input   Salary  : dollar8.;                                                                           
else do;                                                                                                                        
        Name=trim(Name)||' '||temp;                                                                                             
        input temp $  Salary  : dollar8.;                                                                                       
end;                                                                                                                           
DOB=input(temp,mmddyy10.);                        
format DOB date9. Salary dollar8.;                                                                                             
datalines;                                                                                                                              
001 Christopher Mullens  11/12/1955 $45,200                                                                                             
002 Michelle   Kwo  9/12/1955 $78,123                                                                                                   
003 Roger W. McDonald  1/1/1960 $107,200                                                                                                
;                                                                                                                                       
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群