BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rajvijay
Calcite | Level 5

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.


					
				
			
			
				
			
			
			
			
			
			
			
		
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

3 REPLIES 3
jakarman
Barite | Level 11

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 --<-----
Peter_C
Rhodochrosite | Level 12

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

Tom
Super User Tom
Super User

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

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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