I have a line of raw data as follow.
Variables: GenderType Year Total Asofdate
ihe-M 1970 5,044 Retrieved: 03/14/2012 f-IHE 1970 3,537 Retrieved: 03/14/2012
ihe-m 1980 5,874 Retrieved: 03/14/2012 f-IHE 1980 6,223 Retrieved: 03/14/2012
It should have four gendertype but I can only read ihe-M and ihe-m. How to ask SAS to pick up f-IHE and f-IHE.
Even if I put @, it still won't read.
libname Lesson08 '/home/coccus030/sasuser.v94/';
Data Lesson08.college09ds;
Infile '/home/coccus030/sasuser.v94/institutiondata.txt' firstobs=2;
Input GenderType & $6. Year 7-10 Total comma6. @29 AsofDate mmddyy10.;
run;
@elsalam You asked the same question in another thread
https://communities.sas.com/t5/Base-SAS-Programming/unable-to-read-messy-raw-data/m-p/457417#M115972
Kindly do not duplicate the same questions over and over .. Thank you!
Did you check the solution in your other post and did you notice double trailing (@@) which is used to hold the line.
I ensure this code will work but I wonder whether or not it has another way.
I use @@ at SAS studio but it never display the result.
It will continuous to run so I click cancel.
Thx
You can use @@, but you then have to change the INPUT statement. For example, you can't tell SAS to move to column 29 to start reading the date. If you do that, SAS will never get to the end of the line of data (hence you are seeing an infinite loop). You would need to use a style of INPUT that keeps moving from left to right.
Since the format is slightly different on the left vs. the right (two spaces vs. one space separating two of the variables), it's easier to just hard-code all the positions.
Do you have any null values represented as spaces only? There are none in your example.
Variables: GenderType Year Total Asofdate ihe-M 1970 5,044 Retrieved: 03/14/2012 f-IHE 1970 3,537 Retrieved: 03/14/2012 ihe-m 1980 5,874 Retrieved: 03/14/2012 f-IHE 1980 6,223 Retrieved: 03/14/2012
If not then just use list mode input. Why not just read the text in the line to its own variable?
data want ;
infile 'filename' firstobs=2 truncover ;
input GenderType :$10. Year Total :$comma. AsOfType :$12. Asofdate :mmddyy. @@;
format Asofdate yymmdd10. ;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.