Dear community,
I am working on a macro to copy a directory along with all of its content (in SAS EG on a server if relevant) and the issue is that some directories/files have very weird names. Particularly, one of them is named something like "text;text;;*';*" (without double quotes). So to process it correctly I've tried to use %str() function like this:
%let dir_name=%str(text;text;;*';*);
but the last 3 symbols (after the second *) are identified as a comment. I don't get any error but later I can't run any code due to unmatched quotes. Which is another issue because I can't fix it (I tried running the following but it doesn't help:
; *'; *"; );
Returning to the original problem I've found the following workaround:
%let dir_name=%str("text;text;;*';*");
But it is possible that one of the folders/files will contain a double quote resulting in unmatched quotes again. Any suggestions?
Thank you in advance!
UPD: The issue wasn't the ";*" part but the single quote which wasn't masked by %. Now with additional % before the quote it works fine. Thanks everyone and sorry for the silly question. 🙂
You need to show what particular statements are causing you trouble.
But why are you trying to do this with macro code?
Having * and ; in the value of actual character variable will not cause any trouble.
Just have the macro generate actual SAS code.
If you need to pass a string to a macro in as in input parameter then just include the quotes around the values so that the macro processor will ignore them.
%mymacro(filename='strange*;name');
Then the SAS code you just use the value of the macro variable anywhere it could use a string literal.
data _null_;
rc=fdelete( &filename );
put rc=;
run;
UPD: The issue wasn't the ";*" part but the single quote which wasn't masked by %. Now with additional % before the quote it works fine. Thanks everyone and sorry for the silly question. 🙂
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.