- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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,
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Can you please put headers in your text file. Its difficult to understand like this.
Regards,
Anushree
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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. ;