BookmarkSubscribeRSS Feed
JMarkW
Fluorite | Level 6
I'm having difficulty defining a macro variable with the string "/*.dat" in it. if the * is changed to another character value the code works fine.

Is there some type of escape character that needs to proceed a * in this type of string?
7 REPLIES 7
deleted_user
Not applicable
Does surrounding the variable with %STR() or %NRSTR() help?
JMarkW
Fluorite | Level 6
I'm using "call symput" in a data step so the macro commands will not work there.

I'm generating UNIX commands and did find that //*.dat will work while /*.dat will not.
PatrickG
SAS Employee
That won't work. Those two characters in that order and everything that follows up to and including the chars */ in that order are consumed by the lexical analysis phase of the tokenizer, which thinks you're inserting a comment in your code. The trigger for this action is the / followed immediately by the *. That is why no amount of macro quoting will make any difference.
Flip
Fluorite | Level 6
Ok, I took the simple approach to this and it works fine for me.

data _null_;
call symput('badstr', '"ls /*.txt ;"');
run;
x &badstr ;

Putting the quotes into the macro variable works, but quoting in the X command will not. (That is double quotes inside single quotes.)
JMarkW
Fluorite | Level 6
The command is actually very complex grep being created dependent on input data.
JMarkW
Fluorite | Level 6
I did get the following to work. I wonder if the first / escapes the second.

/usr/xpg4/bin/grep -l -E -e '^[^|]*\|[^|]*\|abc\|' -e '^[^|]*\|[^|]*\|defg\|' /dir1/dir2/dir3//*.txt
Peter_C
Rhodochrosite | Level 12
an old post, but one with outstanding value and issues ...
How

%let a= / ;
%let b= /&a.*;
%put %superQ(b) ;
b is established as //*
an alternative to /*.dat as a definition of all dat files, would be /?*.dat
Separating / and * with ? should not reduce the selection of files selected but will remove that troublesome /* combination

peterC

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 1386 views
  • 0 likes
  • 5 in conversation