In order to count the number of SAS Code Lines by program (under windows environment).
As example, Let’s take the following:
Folder /PGM_1.sas
Folder/toto.sas
………
Folder/PGM_N
Is it possible to report the number of the Code lines by Program as follows?
PGM Code lines number
PGM_1.sas XXX
Something like this?
data lines;
length fnam sasfile $200;
infile 'W:\SAS_DK\PersonligeMapper\lasseso\*.sas' filename=fnam end=done;
sasfile=fnam;
do lines=0 by 1 until(fnam ne sasfile or done);
input;
end;
sasfile=scan(sasfile,-1,'\');
output;
run;
Something like this?
data lines;
length fnam sasfile $200;
infile 'W:\SAS_DK\PersonligeMapper\lasseso\*.sas' filename=fnam end=done;
sasfile=fnam;
do lines=0 by 1 until(fnam ne sasfile or done);
input;
end;
sasfile=scan(sasfile,-1,'\');
output;
run;
Thank very much..That's very kind from you.
I got this private message from @mkeintz:
Unfortunately, I am getting correct results from your suggestion only for the first sas program file encountered. I have 4 sas program files in my directory with 5, 5, 5, and 3 lines respectively. But this program reports 5,4,4, and 1.
It looks like the UNTIL fnam^=sasfile occurs at the start of the next fnam. Since your counter starts at zero, its not a problem for the first prog. But that line is not counted for the other files, which are all undercounted by 1. In addition the UNTIL DONE condition occurs at the end of the last program, so it is undercounted by 2.
So, you may have to tweak my program a bit to get things completely right.
I would actually ask for a definition of "line" for this purpose.
A "line" could be a physical line in a file as defined by the OS new line indicator.
A "line" could also be a complete SAS statement as ended by a ;
So how many lines would this be:
proc freq data=sashelp.class; tables sex*age/output out=work.counts. run;
or this:
proc freq
data=sashelp.class
;
tables sex*
age/output
out=work.counts.
run;
I don't find "line counts" terribly informative but that may just be me.
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.