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

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,

 

data.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

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.

View solution in original post

5 REPLIES 5
anushreebiotech
Obsidian | Level 7

Hi,

 

Can you please put headers in your text file. Its difficult to understand like this.

 

Regards,

Anushree

ErikLund_Jensen
Rhodochrosite | Level 12

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.

Astounding
PROC Star

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;

 

dustychair
Pyrite | Level 9
Thank you SO much!
Tom
Super User Tom
Super User

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

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 4015 views
  • 2 likes
  • 5 in conversation