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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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