DATA Step, Macro, Functions and more

how to ask SAS continuous to read data after the last variable

Accepted Solution Solved
Reply
Contributor
Posts: 25
Accepted Solution

how to ask SAS continuous to read data after the last variable

 

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;


Accepted Solutions
Solution
‎04-25-2018 02:01 PM
Super User
Posts: 6,939

Re: how to ask SAS continuous to read data after the last variable

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


All Replies
Frequent Contributor
Posts: 105

Re: how to ask SAS continuous to read data after the last variable

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

PROC Star
Posts: 635

Re: how to ask SAS continuous to read data after the last variable

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
Contributor
Posts: 25

Re: how to ask SAS continuous to read data after the last variable

Posted in reply to SuryaKiran
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.
Solution
‎04-25-2018 02:01 PM
Super User
Posts: 6,939

Re: how to ask SAS continuous to read data after the last variable

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

Contributor
Posts: 25

Re: how to ask SAS continuous to read data after the last variable

Posted in reply to Astounding

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

Super User
Posts: 6,939

Re: how to ask SAS continuous to read data after the last variable

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.

Contributor
Posts: 25

Re: how to ask SAS continuous to read data after the last variable

Posted in reply to Astounding
Thank you for your help.


Your code should work but I want to know the other way on how to
Super User
Super User
Posts: 8,290

Re: how to ask SAS continuous to read data after the last variable

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;

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 231 views
  • 0 likes
  • 5 in conversation