I find “pipe” is quite helpful. I need to replace the old path with a different path so I am thinking to use a macro to do the work.
The old one:
filename DIRLIST pipe 'dir "C:\ab\c\*.txt" /b ';
data dirlist ;
infile dirlist lrecl=200 truncover;
input file_name $100.;
run;
I am thinking to define a sas macro like
%let datapath= d:\ce\fi\gh
And then put &datapath to replace the old path. It seems it does not work. Any advice how to define a sas macro to replace old path// no lib is needed
Thank you
Macro triggers are not resolved inside of single quotes. Use double quotes instead if you want SAS to recognize the reference to the macro variable.
%let datapath= d:\ce\fi\gh ;
filename DIRLIST pipe "dir ""&datapath\*.txt"" /b";
You can use the macro function %SYSFUNC() to call the QUOTE() function to make it easier. That way you do not need to double up the embedded double quote characters in the command string since the QUOTE() function will take care of that for you.
filename DIRLIST pipe %sysfunc(quote(dir "&datapath\*.txt" /b));
Macro triggers are not resolved inside of single quotes. Use double quotes instead if you want SAS to recognize the reference to the macro variable.
%let datapath= d:\ce\fi\gh ;
filename DIRLIST pipe "dir ""&datapath\*.txt"" /b";
You can use the macro function %SYSFUNC() to call the QUOTE() function to make it easier. That way you do not need to double up the embedded double quote characters in the command string since the QUOTE() function will take care of that for you.
filename DIRLIST pipe %sysfunc(quote(dir "&datapath\*.txt" /b));
@Bal23 wrote:
I find “pipe” is quite helpful. I need to replace the old path with a different path so I am thinking to use a macro to do the work.
The old one:
filename DIRLIST pipe 'dir "C:\ab\c\*.txt" /b ';
data dirlist ;
infile dirlist lrecl=200 truncover;
input file_name $100.;
run;
I am thinking to define a sas macro like
%let datapath= d:\ce\fi\gh
And then put &datapath to replace the old path. It seems it does not work. Any advice how to define a sas macro to replace old path// no lib is needed
Thank you
Inside the single quotes, macro variables are not resolved, so &datapath will fail inside single quotes. Instead, try this:
filename DIRLIST pipe "dir ""&datapath\*.txt"" /b ";
Thank you both of you. Yes, it works.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.