BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LineMoon
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

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;

View solution in original post

4 REPLIES 4
s_lassen
Meteorite | Level 14

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;
LineMoon
Lapis Lazuli | Level 10

Thank very much..That's very kind from you.

s_lassen
Meteorite | Level 14

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.

ballardw
Super User

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2349 views
  • 2 likes
  • 3 in conversation