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

Hi.  I have a program that reads in a file one line at a time.  The entire line is read in as a single variable named LINE.  As each line is read in I'm trying to determine if the entire line is blank and flag it with an indicator.  Is there a good way to do this?  I tried this:

 

if line='' then blank_ind =1; 

 

But it's not working. Maybe I have to search for all blanks ending with a special character like a carriage return or something?

 

Any suggestions would be great.  Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

have you tried

if compress(line) = "" then blank_ind = 1;

 

View solution in original post

3 REPLIES 3
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

have you tried

if compress(line) = "" then blank_ind = 1;

 

ScottBass
Rhodochrosite | Level 12

@buechler66 wrote:

But it's not working.

What's not working?  Could your data contain non-printing characters?

 

Try this approach:

 

data test;
   length line clean_line $10 flag1 flag2 8;
   infile datalines4;
   input;
   line=_infile_;
   if _n_=3 then line="00"x;
   clean_line=compress(line,,"kw");
   flag1=missing(line);
   flag2=missing(clean_line);
   putlog (line clean_line) (=$hex20.);
   datalines;
foo
bar
   
blah
;;;;
run;

Then view the log.

 


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
Tom
Super User Tom
Super User

Please show example of how you are reading the lines as the right answer will depend on how you are reading the file.  For example if you use the FLOWOVER option on the INFILE statement (which is the default behavior) then SAS will essentially skip the empty lines since it will go looking for the values to satisfy the INPUT statement.

 

Depending on how you are reading the file you can test if the line was blank. 

if _infile_=' ' then .....

You can also use the LENGTH= on the INFILE statement to have SAS set the value of a variable to the length of the line. Then you could distinguish between a blank line and line with no characters at all.

infile ... length=line_length .... ;
....
if line_length=0 then ...

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 548 views
  • 4 likes
  • 4 in conversation