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?
filename rd 'C:\Users\rakes\Documents\My SAS Files\sas_practice\program_2.sas';
input rec $150.;
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.
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.
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;
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 ;;;;
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;
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 open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.