SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
fgasdg
Calcite | Level 5

I'm looking to  get the output of unix command

 

       %let myfile =  x 'ls -tr /sas/data/mydata | tail -1';

 

to be added into the sas program as a variable  &myfile to use in the program and I can get awa from hardcoded filenames.

Any ideas?

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

You probably want to use a PIPE device, e.g.:

 

filename ls pipe 'ls -tr /sas/data/mydata | tail -1';
data want;
  infile ls;
  input <whatever you want from the input>;  call symputx('myfile',<the variable you read>);
run;

 

 

View solution in original post

3 REPLIES 3
Reeza
Super User

This macro, not mine, will generate the directory listing of a folder into a data set and can recursively search the subfolders. Set the depth to control it not searching. 

 

https://github.com/sasutils/macros/blob/master/dirtree.sas

 

 

s_lassen
Meteorite | Level 14

You probably want to use a PIPE device, e.g.:

 

filename ls pipe 'ls -tr /sas/data/mydata | tail -1';
data want;
  infile ls;
  input <whatever you want from the input>;  call symputx('myfile',<the variable you read>);
run;

 

 

fgasdg
Calcite | Level 5

Exactly what I needed. Works perfectly! thanks!

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 3 replies
  • 1716 views
  • 1 like
  • 3 in conversation