BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kaushik2
Fluorite | Level 6

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.saslibname TERADATA "/abc/def";
pgm2.sas   libname TERADATA "/xyz/";

 

Please help. Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

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.

RichardDeVen
Barite | Level 11

 

fvar = catx(" ","grep -i teradata",fname,'2>&1');
Kaushik2
Fluorite | Level 6

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.

Kurt_Bremser
Super User

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.

Kaushik2
Fluorite | Level 6
Thanks for the details and your valuable tips

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 1971 views
  • 5 likes
  • 3 in conversation