BookmarkSubscribeRSS Feed
u63406443
Calcite | Level 5

Hi All,

 

I am trying reading  the entire SAS  program (.sas files) and storing entire program code in the dataset using option filename statement, but here problem is it is not able to fetch all lines of code instead fetching few lines. Can anyone please help me?

 

code:

filename rd 'C:\Users\rakes\Documents\My SAS Files\sas_practice\program_2.sas';

data temp;
infile rd;
input rec $150.;
run;

 

Thanks,

Rakesh.

7 REPLIES 7
Kurt_Bremser
Super User

Why do you want to do this? Programs are stored best in their text form.

 

The default value for an overflow while reading an external file is MISSOVER, so any line shorter than 150 characters will cause a missing value.

Change your code:

data temp;
infile "C:\Users\rakes\Documents\My SAS Files\sas_practice\program_2.sas" truncover;
input rec $150.;
run;

Since you seem to get some lines with your original code, you may have to increase the informat, and also set a proper LRECL= option in the INFILE statement.

u63406443
Calcite | Level 5

Hi Kurt_Bremser,

 

I need below program, because I merging almost 60 SAS codes, and filtering with a condition. I truly appreciate the update; it's been quite useful.

 

Thank you Kurt_Bremser

Patrick
Opal | Level 21

If this is for some sort of impact analysis like to find all programs that use a certain table:

I used to use Atom for such tasks but this tool got unfortunately depreciated. 

 

You could still use Notepad++ to search through all .sas programs under a folder or even folder and sub-folders

Patrick_0-1700549266340.png

 

Or for files under Linux/Rhel a grep command is often fit for purpose - potentially in combination with a find command.

 

If you want to use SAS for such a search then you could use the infile statement with a wildcard which would allow to write code that reads all .sas files in a folder in one go.

 

 

Ksharp
Super User
filename rd 'C:\temp\a.sas';

data temp;
infile rd length=len;
input rec $varying200. len;
run;
u63406443
Calcite | Level 5

Thank you Ksharp.

yabwon
Onyx | Level 15

Yet another way, with getting the buffer:

filename rd 'C:\SAS_PACKAGES_DEV\SPFinit.sas';

data temp;
  infile rd;
  input;
  length rec $ 256;
  rec = _infile_;
run;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Tom
Super User Tom
Super User

Because you used the default FLOWOVER setting for the INFILE statement when you tried to read past the end of a line SAS went to the next line to find the data.

 

Let's use an example using in-line data (requires informat longer than 80 since in-line data is padded to next multiple of 80 column card image).

data test;
  input line $100.;
cards4;
line one
line two
line three
line four
line five
;;;;

Result

Tom_0-1700579803754.png

You want to use the TRUNCOVER option.

You also want to use $CHAR informat to preserve any leading spaces on the lines.

data test;
  infile cards truncover;
  input line $char100.;
cards4;
filename rd 'C:\Users\rakes\Documents\My SAS Files\sas_practice\program_2.sas';

data temp;
  infile rd;
  input rec $150.;
run;

;;;;


proc print;
run;

Result

 Obs    line

 1     filename rd 'C:\Users\rakes\Documents\My SAS Files\sas_practice\program_2.sas';
 2
 3     data temp;
 4       infile rd;
 5       input rec $150.;
 6     run;
 7



SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 7 replies
  • 1378 views
  • 2 likes
  • 6 in conversation