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