Reputation: 29
I am trying to read the following txt dataset in SAS but unfortunely, I only get half of the dataset information in my final table. The file is
Kreil Professional M 823421 Natan Expert M 234 Silvio Beginner M 2342 Steven Unexperienced M 2343
Anton Expert M 76575 Sophia Professional F 79 Cecilia Unexperienced F 78585 Michael Professional M 23424
Kelly Expert F 43212 Kevin Beginner M 23532 Sarah Beginner F 23523 Emmanual Beginner M 234542
Andre Unexperienced M 3242 Valerie Expert F 2342 Jesper Professional M 2141 Michael Unexperienced M 4141
Benoit Unexperienced M 3425 Nicolas Expert M 765757 Alice Beginner F 57858 Madelaine Expert F 2412
I used the following code:
INFILE "path/File/data.txt";
INPUT Name $ Experience $ Sex $ Salary $ ;
run;
Proc print data=Data;
proc sort data=data OUT=Data_n;
BY DESCENDING Salary Name Experience Sex Salary;
RUN;
proc print data=Data_n;
As a result, I got:
1 Alex Professional M 37884
2 Kreil Professional M 823421
3 Anton Expert M 76575
4 Kelly Expert F 43212
5 Andre Unexperience M 3242
6 Benoit Unexperience M 3425
The information contained in the other half of each row is missing. How can I solve this please? Thank you.
Upvotes: 0
Views: 40
Reputation: 5452
Try using the Double Trailing @ Line-Hold Specifier. This tells SAS to keep reading fields on the same line without moving to the next line. It looks like your input file is formatted as per the example shown in the SAS help here: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/basess/n068wqvbjnndvjn17mqpoxdj7te7.htm
Your new code would have an input statement like this:
INPUT Name $ Experience $ Sex $ Salary $ @@;
Each time SAS reaches the @@, if it is not at the end of a line, it will go back and try to pick up Name
, Experience
, Sex
and Salary
again, from the same line.
Upvotes: 2