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.
have you tried
if compress(line) = "" then blank_ind = 1;
@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 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 ...
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.