Hi,
I would like to import raw data that has multiple observation in a single record. each records start with a identifyer variable. the following example show the data with the sas code i am using. It works fine :
raw data :
1824 1,323.34 2,472.85
1943 1,908.34
2046 1,423.52 1,673.46 3,276.65
2063 2,345.34 2,452.45 3,523.52 2,983.01
data excedata;
infile mydat(excedata.txt) missover;
input id sales : comma. @ ;
do while (sales ne .);
output;
input sales : comma. @;
end;
run;
Howver when I want to use the same coding strucutre for this data I got invalid message in my log
182-04-7814 09FEB99 530 04MAY99 610
302-57-5023 09FEB99 480 04MAY99 530
123-89-8470 09FEB99 560 04MAY99 570 13JUL99 610
152-64-0014 09FEB99 780
813-63-7456 09FEB99 790
data satdat2;
infile mydat(satdata2.txt) missover ;
input ssn $11. @13 date date7. @21 code 3. @ ;
do while (code ne .);
output;
input date date7. code 3. @ ;
end;
run;
it says invalide data for code. Any clue ?
Cheers
Skp
data have; infile '/folders/myfolders/test.txt' truncover; input ssn : $11. date : date7. code @ ; do while (code ne .); output; input date : date7. code @ ; end; format date date7.; run;
Notice that in your first program you have INPUT SALES : comma. @; the colon : is the key to using an INFORMAT in an input statement with LIST input. You could alternatively use an INFORMAT statement to associate the INFORMATS and just use variables names in the input statement.
informat sales comma.;
input sales @;
Generally it helps to post the log with code and error messages.
Note that the first part of your input has read @ specific columns. But the loop doesn't do that. So with the formats on the input it forces reading at the columns the previous field ended. So you end up with the code trying to read the last character of the date a space and the first character of the code. Since the code is numeric an imbedded space is invalid to read. You can avoid that by @data_null__'s suggestion of adding informat statements and leaving the formats off the input statements tranforming the code to list input OR add appropriate +n to shift the start column over to the start of the variable.
data have; infile '/folders/myfolders/test.txt' truncover; input ssn : $11. date : date7. code @ ; do while (code ne .); output; input date : date7. code @ ; end; format date date7.; run;
Thanks Ksharp !
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.