Dear Experts,
Suppose I have a dataset "A" like below with variable called fname.
fname |
pgm1.sas |
pgm2.sas |
Now I need a Linux command to be executed for every observation to the above dataset and capture output in RESULT variable. Lets say, I want to search for a word TERADATA in the programs. so, need to execute grep command for every observation and capture its Linux output
grep TERADATA pgm1.sas ,
grep TERADATA pgm2.sas
and so on...
So, my output dataset should look like :
fname | RESULT |
pgm1.sas | libname TERADATA "/abc/def"; |
pgm2.sas | libname TERADATA "/xyz/"; |
Please help. Thanks.
Run a "dynamic pipe":
data want;
set have;
fvar = catx(" ","grep",fname,'2>&1');
infile dummy pipe filevar=fvar truncover end=done;
do until (done);
input response $100.;
output;
end;
run;
Edit: see @RichardDeVen 's correction of the UNIX command.
Run a "dynamic pipe":
data want;
set have;
fvar = catx(" ","grep",fname,'2>&1');
infile dummy pipe filevar=fvar truncover end=done;
do until (done);
input response $100.;
output;
end;
run;
Edit: see @RichardDeVen 's correction of the UNIX command.
fvar = catx(" ","grep -i teradata",fname,'2>&1');
Thanks a lot @Kurt_Bremser and @RichardDeVen
I am actually trying to prepare a prototype which can Read a SAS program along with its associated logs from a predefined folder and extract various details about program like datasets, filename, libraries used ,macro variables resolution (by Grep' command to access macro variable entry from log file) into a Excel spreadsheet.
Hoping this prototype can serve as solution to Business Analysts kind of folks who may not be technologically adept but to get insights of a SAS program rather quickly. I am halfway already but the excel report shows more of non-organized data.
Wanted to know if there are any such similar tools / program available which we can leverage?. Please advise.
Have a look at PROC SCAPROC.
But, IMO, you need to start up front. Before writing code, have a clear definition of requirements, and a design coming from that. Then, while you write the code, or IMMEDIATELY afterward, document what you have done.
This documentation must include an exhaustive description of data going in and data coming out, making the program a "black box" where you do not have to look into to know what it does. This documentation will be the place where you direct your analysts for information.
If you do not have such documentation at the moment, start creating it NOW. Your organization may already have a documentation framework in place, so integrate yours there.
With the introduction of Data Integration, SAS provides a complete framework for this.
Keep in mind that 90% of a good coders work is coding, and another 90% documentation. See Maxim 16.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.