SAS-Macro using doubles quotes filename pipe

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

SAS-Macro using doubles quotes filename pipe

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.


					
				
			
			
				
			
			
			
			
			
			
			
		

Accepted Solutions
Solution
‎08-03-2014 05:08 PM
Super User
Super User
Posts: 6,364

Re: SAS-Macro using doubles quotes filename pipe

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));

View solution in original post


All Replies
Valued Guide
Posts: 3,206

Re: SAS-Macro using doubles quotes filename pipe

You can avoid de piping for getting a list of name at all using wildcars.

http://support.sas.com/documentation/cdl/en/hostunx/67285/HTML/default/viewer.htm#p1cycu6ky2lsd7n0zq...

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.

---->-- ja karman --<-----
Valued Guide
Posts: 2,174

Re: SAS-Macro using doubles quotes filename pipe

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

Solution
‎08-03-2014 05:08 PM
Super User
Super User
Posts: 6,364

Re: SAS-Macro using doubles quotes filename pipe

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));

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 1149 views
  • 7 likes
  • 4 in conversation