BookmarkSubscribeRSS Feed
BCNAV
Quartz | Level 8

I have the following:

 

%let dir_of_tracks=\\ncrfp4\AtlanticAnalysis\NAT Track Analysis\Track Data\Nov-2018;

 


filename DIRLIST pipe 'dir "\\ncrfp4\AtlanticAnalysis\NAT Track Analysis\Track Data\Nov-2018\NatTrackDetails_2*.csv" /b ';

 

call symputx('read'||put(count,4.-l),cats('\\ncrfp4\AtlanticAnalysis\NAT Track Analysis\Track Data\Nov-2018\',file_name));

 

 

 

I would like to replace the paths in the filename DIRLIST pipe commands with the macro variable dir _of_tracks that you see declared. Of course the filename DIRLIST pipe line has quotes, as does the call symputx below it/

 

 

How can I add in the &dir_of_tracks within these double and single quotes.....probably easy, but these details I always forget. Quotes always mess me up.

4 REPLIES 4
Astounding
PROC Star

To get macro variables to resolve you need to use the doublequotes on the outside, and single quotes (if needed) on the inside.  In that case, this means:

 

%let dir_of_tracks=\\ncrfp4\AtlanticAnalysis\NAT Track Analysis\Track Data\Nov-2018;

 

What you have:


filename DIRLIST pipe 'dir "\\ncrfp4\AtlanticAnalysis\NAT Track Analysis\Track Data\Nov-2018\NatTrackDetails_2*.csv" /b ';

 

What you should have instead:


filename DIRLIST pipe "dir '&dir_of_tracks.\NatTrackDetails_2*.csv' /b ";

Tom
Super User Tom
Super User

You need to use double quote characters as the outside quotes. The macro processor ignores strings inside of single quotes. Plus the DOS command line needs quotes around paths that can contain spaces or else the spaces will be interpreted as delimiting new arguments for the commands.  When you want to have a quote as parted of a quoted string you need to double up those embedded quotes.

filename DIRLIST pipe "dir /b ""&dir_of_tracks\NatTrackDetails_2*.csv""";

I find that the QUOTE() function is useful for this.

For example you could generate the command as a dataset variable which you can pass to the INFILE statement using the FILEVAR= option.

data filelist;
  length cmd $200;
  cmd=catx(' ','dir /b',quote(catx('\',"&dir_of_tracks",'NatTrackDetails_2*.csv')));
  infile dummy pipe filevar=cmd  truncover;
  input filename $256. ;
run;

Or you can use the macro function %SYSFUNC() to let you use the QUOTE() function to generate code:

filename DIRLIST pipe %sysfunc(quote(dir /b "&dir_of_tracks\NatTrackDetails_2*.csv"));

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 821 views
  • 0 likes
  • 4 in conversation