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

 

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Here's what can be used to replace the INPUT statement:

 

input GenderType $ 1-5   year 7-10  @11 total comma6. @29 AsofDate mmddyy10. @;

output;

input GenderType $ 40-44  year 46-49  @51 total comma6.  @69 AsofDate mmddyy10.;

output;

format asofdate yymmdd10.;

View solution in original post

8 REPLIES 8
MarkWik
Quartz | Level 8

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

SuryaKiran
Meteorite | Level 14

Did you check the solution in your other post and did you notice double trailing (@@) which is used to hold the line.

 

http://documentation.sas.com/?docsetId=basess&docsetTarget=n068wqvbjnndvjn17mqpoxdj7te7.htm&docsetVe...

Thanks,
Suryakiran
elsalam
Calcite | Level 5
I am self learning so I use SAS studio.


Whenever I put @@ at SAS studio, the output will keep running and never display the result.


therefore, I thought SAS studio won't work with @@.


I don't know computer language well enough to understand the issue so my thought might be kind of stupid.
Astounding
PROC Star

Here's what can be used to replace the INPUT statement:

 

input GenderType $ 1-5   year 7-10  @11 total comma6. @29 AsofDate mmddyy10. @;

output;

input GenderType $ 40-44  year 46-49  @51 total comma6.  @69 AsofDate mmddyy10.;

output;

format asofdate yymmdd10.;

elsalam
Calcite | Level 5

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

Astounding
PROC Star

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.

elsalam
Calcite | Level 5
Thank you for your help.


Your code should work but I want to know the other way on how to
Tom
Super User Tom
Super User

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;

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 1128 views
  • 0 likes
  • 5 in conversation