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

Hi,

 

So this is similar but different from previous posts.

 

I am trying to create a list of directories (not files) in a DIS project.

In DIS I can get a list of all the folder contents using x ls -lp &file_path. >/tmp/folderlisting.csv; 

 

In Bash script ls -d */ "filepath" works perfectly. However the */ is not working in SAS as it treats this as a comment end. Quoting this has not helped.

 

So, any help I could get in finding a solution or alternative to x ls -d */ "&filepath." >/tmp/folderlisting.csv; would be appreciated.

 

I am aware that could use multiple lines of code to search through the full output and create a new file but i am looking for an efficient streamlined solution.

 

NB I have also tried | grep ^d but again DIS doesn't like this.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Try SYSEXEC or CALL SYSTEM instead of an X command. You can enclose your command in quotes which will help it process correctly.

View solution in original post

4 REPLIES 4
Reeza
Super User
Try SYSEXEC or CALL SYSTEM instead of an X command. You can enclose your command in quotes which will help it process correctly.
JordanWood
Fluorite | Level 6

Thanks for the help. I tried lots of the variants suggested but the one that worked is ;

 

%sysexec (ls -l "&file_path" | grep ^d  > /tmp/folderlisting.csv);

 

also had to do some double quoting of the variable file_path when setting it but that is all part of the differences in EG and DIS.

Kurt_Bremser
Super User

Use the filename pipe method:

filename oscmd pipe "ls -d */ '&filepath.' 2>&1";

data _null_;
infile oscmd;
input;
put _infile_;
run;

Then look at the log and see how you can use the output of the ls.

Tom
Super User Tom
Super User

I wouldn't use the X command, but if you do then add quotes around the command you want to run so that the command does not get interpreted by SAS or the SAS macro processor.

filename list temp;

x "ls -d ~/*/ > '%sysfunc(pathname(list))'" ;
data _null_;
  infile list ;
  input;
  put _infile_;
run;

Or easier still just use the PIPE engine and skip the temporary file.

data _null_;
  infile "ls -d ~/*/" pipe ;
  input ;
  put _infile_;
run;

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 4 replies
  • 4460 views
  • 1 like
  • 4 in conversation