I am using the following Macro that uses filename pipe. But get an error saying invalid option name "dir", etc. I suspect it could be due to the quotes while defining filename and pipe. I am not sure how to have it so that SAS doesnt recognize dir as an option.
I tried to remove the quote, removing %bquote and having just the double quote, but still keep getting the errors.
I am using Windows, but will also be running it remotely on Linux. Any thoughts would be deeply appreciated. Thank you so much for your time.
%macro setprogvar(dateval);
%global date;
%let date=&dateval;
%put &date;
%put &dateval;
%let filepath = %bquote("C:\Research\SASDataSets\bulk all data &date");
filename CDR_Bulk pipe "dir &filepath /a:-d-h-s /b /s";
%mend setprogvar;
%setprogvar(20100331);
***LOG************
1 filename CDR_Bulk pipe "dir &filepath /a:-d-h-s /b /s";
--- 23 ERROR 23-2: Invalid option name dir.
1 ! filename CDR_Bulk pipe "dir &filepath /a:-d-h-s /b /s";
- 23 ERROR 23-2: Invalid option name a.
Let SAS deal with the quotes for you.
%let filepath = "C:\Research\SASDataSets\bulk all data &date";
filename CDR_Bulk pipe %sysfunc(quote(dir &filepath /a:-d-h-s /b /s));
Or even better make it so that users can supply quoted or unquoted path names.
%let filepath = C:\Research\SASDataSets\bulk all data &date;
%let filepath = %sysfunc(quote(%qsysfunc(dequote(&filepath))));
filename CDR_Bulk pipe %sysfunc(quote(dir &filepath /a:-d-h-s /b /s));
You can avoid de piping for getting a list of name at all using wildcars.
http://support.sas.com/documentation/cdl/en/hostwin/67279/HTML/default/viewer.htm#chfnoptfmain.htm
When processing csv / dat / txt for input processing this will eliminate alle processing making that list.
Using the filevar option at the input statement will give the real name.
You can use a predefined filename (Windows / Unix) and then using the infile fileref(*&data) those files processed
It is possible the develop a macro solving all what you are trying to do.
It will get into a lot of complexity as the quotes are needed in the path for Windows conventions while you are coding in different quoting meanings with sas-macros.
Did you verify piping is allowed in Unix? That one is getting blocked often introducing a approach difference.
There are SAS functions for introduced to get around that (not easy).
The macro quoting sometimes is requiring unquoting before usage: http://support.sas.com/documentation/cdl/en/mcrolref/64754/HTML/default/viewer.htm#p1k3cotqhvgwk0n10...
That are 3 possible answers to solve your question.
Rather than use %bQuote() attempting to protect quotes in a macro variable value, just use plain text for the filepath value and use the rule for quoting embedded quotes.
Here is the demo - only a short way from your original.
filename CDR_Bulk pipe "dir ""&filepath"" /a:-d-h-s /b /s";
good luck
peterC
Let SAS deal with the quotes for you.
%let filepath = "C:\Research\SASDataSets\bulk all data &date";
filename CDR_Bulk pipe %sysfunc(quote(dir &filepath /a:-d-h-s /b /s));
Or even better make it so that users can supply quoted or unquoted path names.
%let filepath = C:\Research\SASDataSets\bulk all data &date;
%let filepath = %sysfunc(quote(%qsysfunc(dequote(&filepath))));
filename CDR_Bulk pipe %sysfunc(quote(dir &filepath /a:-d-h-s /b /s));
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.