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. 🙂
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.