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.
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.
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.