DATA Step, Macro, Functions and more

skip blank dataline

Reply
N/A
Posts: 0

skip blank dataline

I have column formats in the raw data with the same variable going accross four different columns. I have blank lines in the data where variables statename and age should be. How do I get SAS to skip these blank lines and move down to the next line within the same column instead of going back to the first column and pulling data from there? Any help would be appreciated. Thanks
N/A
Posts: 0

Re: skip blank dataline

Posted in reply to deleted_user
Can you illustrate this? I can't understand the problem.
Super Contributor
Super Contributor
Posts: 3,174

Re: skip blank dataline

Posted in reply to deleted_user
You will need to use a combination of INPUT with column location pointer to read up each of your data records, first reading the leading columns followed by your columnar-oriented data columns. Then if you decide it is appropriate, only OUTPUT under the appropriate conditions, as you decide while doing your INPUT logic in a DATA step. With this approach/technique, you will likely need to consider using a RETAIN statement for the variables that are blank, as you have described. A sample DATA step is shown below using the SAS DATA step programming techniques mentioned above.

Scott Barry
SBBWorks, Inc.

DATA ;
INFILE DATALINES;
INPUT @1 VAR1 $CHAR2. @4 VAR2 $CHAR1. @6 VAR3 2. VAR4 2.;
IF VAR1 = ' ' THEN VAR1 = LVAR1;
IF VAR2 = ' ' THEN VAR2 = LVAR2;
PUTLOG '>BEFORE_OUTPUT>' / _ALL_;
OUTPUT;
LVAR1 = VAR1;
LVAR2 = VAR2;
RETAIN LVAR1 LVAR2 ' ';
DATALINES;
AA B 1122
3344
BB C 2233
4455
RUN;
Ask a Question
Discussion stats
  • 2 replies
  • 207 views
  • 0 likes
  • 2 in conversation