BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
deleted_user
Not applicable
Can you illustrate this? I can't understand the problem.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 1222 views
  • 0 likes
  • 2 in conversation