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:
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;
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;