BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
DariaKarpova318
SAS Employee

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. 🙂

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

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;

 

svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10
Sometimes I need a different macro quoting function depending on the characters that are in the value. E.g., %SUPERQ() is an example of a macro quoting function that can mask more symbols than the other macro quoting functions.

https://documentation.sas.com/doc/en/mcrolref/1.0/p0ldeqll9sabzcn1jxnvid754b3t.htm
DariaKarpova318
SAS Employee

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. 🙂

DariaKarpova318
SAS Employee
Also as a better alternative to masking every quote I've used %nrbquote (also %bquote) which don't require %.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 654 views
  • 1 like
  • 3 in conversation