BookmarkSubscribeRSS Feed
anming
Pyrite | Level 9

I have a txt file test1.txt: 36 95 (with one space between) and try to load to SAS table through the following codes:

 

data test2;
infile "/folders/myfolders/test1.txt";
input @1 height 2.
@4 weight 2.;
run;

 but if I miss period in the second format @4 weight 2; the test2 will be 36 2. if change to @4 weight 1, test2 will be 36 7. Looks the result is not expected. Anyway, this is a wrong code. 

2 REPLIES 2
Reeza
Super User
data test2;
infile "/folders/myfolders/test1.txt" dlm = ' ' truncover;
input  height  weight ;
run;

What about something more basic like the following but more specifications on the INFILE statement?

 


@anming wrote:

I have a txt file test1.txt: 36 95 (with one space between) and try to load to SAS table through the following codes:

 

data test2;
infile "/folders/myfolders/test1.txt";
input @1 height 2.
@4 weight 2.;
run;

 but if I miss period in the second format @4 weight 2; the test2 will be 36 2. if change to @4 weight 1, test2 will be 36 7. Looks the result is not expected. Anyway, this is a wrong code. 


 

PhilC
Rhodochrosite | Level 12

I think that when you remove the period then SAS stops recognizing the format but then starts to interpret the number as the column number.  It then takes the single digit and places it in weight. I could not replicate getting the "7" using datalines.   

data test2;
  infile datalines;
  input @1 height 2. 
        @4 weight 1; *Chnaging this 1,2,3,4,5;
datalines;
36 95
;
run;
replacing: returns
1 3
2 6
3 .
4 9
5 5

About the unexpectedness: I don't thin this syntax is itself "expected", so being unexpected syntax I'm sure the result is unexpected too. 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 498 views
  • 2 likes
  • 3 in conversation