全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2937 10
2012-11-16
E 1232 JOHN SMITH      15OCT1988
S 1988 34,456
S 1989 37,453
S 1990 40,710
The header record (E) contains data for employee ID, name, andemployment date 。
There is one salarydetail record (s) for each yearthe employee has worked for the company.
Create a SAS data set named HISTORY that contains the variables IDNUM,NAME, YEAR, and SALARY.
like:
  IDNUM     NAME     YEAR     SALARY   
  1232      JOHN SMITH     1988      34,456   
  1232      JOHN SMITH     1989      37,453   
  1232      JOHN SMITH     1990      40,710   


二维码

扫码加我 拉你入群

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

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

全部回复
2012-11-16 10:37:16
/或#
二维码

扫码加我 拉你入群

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

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

2012-11-16 11:29:00
SAS data step can deal with all sort input format. Here is a way to use the trailing @ to control different inputing streams.

data tmp;
length IDNUM 8 NAME $16 YEAR SALARY 8 chk $1;
retain IDNUM NAME;
informat SALARY comma7.;
format SALARY comma7.;
infile cards;
input @1 chk 1 @;
if chk ='E' then input IDNUM 3-6 name 8-23;
else if chk='S' then do;
   input YEAR 3-6 SALARY;
   output;
end;
cards;
E 1232 JOHN SMITH      15OCT1988
S 1988 34,456
S 1989 37,453
S 1990 40,710
E 2222 JOHN DOE        15OCT1988
S 1988 34,456
S 1989 37,453
;
proc print;run;
二维码

扫码加我 拉你入群

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

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

2012-11-16 11:56:42
wangfengxi 发表于 2012-11-16 10:37
/或#
数据集中每个name的salarydetail record(s)不一样
二维码

扫码加我 拉你入群

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

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

2012-11-16 16:22:45
想了半天用了这种方法……我觉得data步特别不方便……TT还在学习中……

data a (keep=idnum name year salary);
input type $ idnum1 name1 $ 8-18;
if type='E' then do; idnum=idnum1; name=name1; retain idnum; retain name; delete; end;
else do; year=idnum1; salary=input(name1,comma10.); end;
format salary comma10.;
cards;
E 1232 JOHN SMITH      15OCT1988
S 1988 34,456
S 1989 37,453
S 1990 40,710
E 2222 JOHN DOE        15OCT1988
S 1988 34,456
S 1989 37,453
;
run;
二维码

扫码加我 拉你入群

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

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

2012-11-16 16:26:24
bobguy 发表于 2012-11-16 11:29
SAS data step can deal with all sort input format. Here is a way to use the trailing @ to control di ...
囧啊……之前本来想用行指针#,但是死活不知道怎么把行指针往上移一行……@是个好东西,受益匪浅……学习啦~
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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