BookmarkSubscribeRSS Feed
soujanyak
Fluorite | Level 6

Hi, 

Please let me know, if there is any code that counts the lines in the sas code.

Thank you

Soujanya

9 REPLIES 9
ballardw
Super User

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).

brzcol
SAS Employee

Try looking at this post and see if it helps with your question: Reporting the SAS Code Lines by Program

bebess
Quartz | Level 8

Is it possible to exclude blank lines from the script ? 

bebess
Quartz | Level 8
exclude them in the count
PeterClemmensen
Tourmaline | Level 20

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.

Kurt_Bremser
Super User
%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.

FreelanceReinh
Jade | Level 19

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).

bebess
Quartz | Level 8

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;

AMSAS
SAS Super FREQ

If you are in the SAS Windowing Environment
Turn on NUMS

 

AMSAS_0-1635176125169.png

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 9 replies
  • 2945 views
  • 6 likes
  • 8 in conversation