Hi all,
I have a data set as in the picture (I'm not copying the data because I want you to see that I have missing values).The data has 108 items' scores (one digit) and then id1 (8 digits) (no space between items and id) and then one space and id2 (3 digits). The spaces you see are missing values not tab or any type of delimiter for items and id1. When I use infile statement all items are in one column. Could you help me to read this data?The txt file in the attachment has the data.
Thank you,
Hi @dustychair
To read fixed-column input like this, you can take advantage of using the @column - notation in the Input statement. This gives you full control over the cursor position:
data test(drop=i);
infile "c:\temp\data.txt";
array score s1-s108;
do i = 1 to 108;
input @i score{i} 1. @;
end;
input @109 id1 8. @119 id2 $3.;
run;
By the way, there are 2 spaces between ID1 and ID2 in your data. The code above reflects that.
Hi,
Can you please put headers in your text file. Its difficult to understand like this.
Regards,
Anushree
Hi @dustychair
To read fixed-column input like this, you can take advantage of using the @column - notation in the Input statement. This gives you full control over the cursor position:
data test(drop=i);
infile "c:\temp\data.txt";
array score s1-s108;
do i = 1 to 108;
input @i score{i} 1. @;
end;
input @109 id1 8. @119 id2 $3.;
run;
By the way, there are 2 spaces between ID1 and ID2 in your data. The code above reflects that.
A good solution, Also note that you can read sequentially without worrying about the starting position:
data test(drop=i);
infile "c:\temp\data.txt";
array score s1-s108;
do i = 1 to 108;
input score{i} 1. @;
end;
input id1 8. @119 id2 $3.;
run;
The data has 108 items' scores (one digit) and then id1 (8 digits) (no space between items and id) and then one space and id2 (3 digits).
Just translate your description into an INPUT statement. Use formatted input instead of list mode.
input (score1-score108) (1.) id1 $8. +1 id2 $3. ;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.