- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello - I'm trying to code a PIPE statement into a macro. The PIPE statement includes a macro variable name (&pathnm) surrounded by wildcard characters (*). When trying the lines below, I get "ERROR: Open code statement recursion detected." Where is my syntax wrong? Thanks for any tips you can provide.
I did search in the community for similar topics, and I tried surrounding the piece with an extra set of quotes (version 2 further down).
filename output pipe "ls -a /mypath/subfolder/*&pathnm*.csv" ;
Version 2 - same error:
filename output pipe "ls -a ""/mypath/subfolder/*&pathnm*.csv"" " ;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Can you show the working command with the same value but not macro variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
And the above working version is outside the macro
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would try
filename output pipe "ls -a /mypath/subfolder/*&pathnm.*.csv"
without the . immediately after your macro variable SAS is likely looking for a macro variable named &pathnm* which is not a valid macro variable name. The dot indicates the resolved value of the macro variable is to be concatenated with the following characters.
Typically we get a "macro variable not found" sort of error message but the * may be treated differently resulting in the "open code recursion" error message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Are you sure your macro variable PATHNM exists? The recursive reference message is sometimes related to that as when the SAS macro processor sees that the macro variable doesn't exist then it just leaves the reference, including the leading & character, in place for SAS to deal with.
But usually when trying to use * wild card in generating a unix path it is the presence of the /* that causes a lot of trouble as it looks like an opening of a block comment. That can end up "eating" a lot of you code and causing all kinds of error message in later pieces of code just because the beginning of the code got cut off by the comment block.
You could try adding macro quoting around one of those two characters.
You can also use the QUOTE() function to add the quotes (and double any embedded quotes in your macro variable).
filename filelist pipe %sysfunc(quote(ls -a /mypath/subfolder/%str(*)&pathnm%str(*).csv,"'")) ;
You could change your Unix command so that the /* is not needed.
filename filelist pipe %sysfunc(quote(cd /mypath/subfolder/; ls -a *&pathnm*.csv,"'")) ;
But then you will need to add the prefix back to the generated list of filenames.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You have something in your macro before that code that causes the problem.
See this short example:
%let pathnm=myfiles;
%macro mymac;
filename output pipe "ls -a /mypath/subfolder/*&pathnm*.csv";
%mend;
%mymac
filename output list;
The log from that:
27 %let pathnm=myfiles; 28 %macro mymac; 29 filename output pipe "ls -a /mypath/subfolder/*&pathnm*.csv"; 30 %mend; 31 %mymac 32 33 filename output list; NOTE: Fileref= OUTPUT Physical Name= ls -a /mypath/subfolder/*myfiles*.csv
So you can see that the filename statement works perfectly well in a macro on its own. Reduce your macro to this, and then expand it step-by-step until the problem reappears.