BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
saskapa
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

4 REPLIES 4
data_null__
Jade | Level 19

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

 

ballardw
Super User

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.

Ksharp
Super User
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;

saskapa
Quartz | Level 8

Thanks Ksharp !

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 996 views
  • 2 likes
  • 4 in conversation