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.
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.
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
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
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.
filename rd 'C:\temp\a.sas';
data temp;
infile rd length=len;
input rec $varying200. len;
run;
Thank you Ksharp.
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
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
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
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!
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.
Ready to level-up your skills? Choose your own adventure.