Hi,
Please let me know, if there is any code that counts the lines in the sas code.
Thank you
Soujanya
You can read a SAS program file like any other text file.
The question to you would be your definition of "line" in this case. Easy to count line feeds, other wise you have to parse code if you want "logical" lines, means start to end of a statement (those pesky ; characters).
Try looking at this post and see if it helps with your question: Reporting the SAS Code Lines by Program
Is it possible to exclude blank lines from the script ?
Very simple code to get the lines into a SAS Data set
data lines;
infile "Path";
input;
line = _infile_;
run;
From there, it should be easy to count the non blank lines.
%let path = /home/myself/sas_programs;
data lines;
length filename fvar $200;
retain filename count;
infile "&path./*.sas" filename=fvar end=done;
input;
if fvar ne filename or done
then do;
if filename ne ""
then do;
if done and _infile_ > " " then count + 1;
output;
end;
count = 0;
filename = fvar;
end;
if _infile_ > " " then count + 1;
run;
This will count all non-empty lines in all SAS programs in the directory.
Nice line counting program. I'm just wondering if the criterion for non-empty lines should rather be _infile_ ne " " to include lines in the count that are indented with ugly tab characters ('09'x < '20'x = " " in ASCII).
Yes you're right i've checked and it works fine : thanks to both of you
%let path = /home/myself/sas_programs;;
data lines;
length filename fvar $200;
retain filename count;
infile "&path./*.sas" filename=fvar end=done;
input;
if fvar ne filename or done
then do;
if filename ne ""
then do;
if done and _infile_ ne " " then count + 1;
output;
end;
count = 0;
filename = fvar;
end;
if _infile_ ne " " then count + 1;
run;
If you are in the SAS Windowing Environment
Turn on NUMS
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.