DATA Step, Macro, Functions and more

symput a macro variable with "/*.dat" in the string

Reply
Contributor
Posts: 55

symput a macro variable with "/*.dat" in the string

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?
N/A
Posts: 0

Re: symput a macro variable with "/*.dat" in the string

Does surrounding the variable with %STR() or %NRSTR() help?
Contributor
Posts: 55

Re: symput a macro variable with "/*.dat" in the string

Posted in reply to deleted_user
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.
SAS Employee
Posts: 58

Re: symput a macro variable with "/*.dat" in the string

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.
Super Contributor
Posts: 359

Re: symput a macro variable with "/*.dat" in the string

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.)
Contributor
Posts: 55

Re: symput a macro variable with "/*.dat" in the string

The command is actually very complex grep being created dependent on input data.
Contributor
Posts: 55

Re: symput a macro variable with "/*.dat" in the string

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
Valued Guide
Posts: 2,177

Re: symput a macro variable with "/*.dat" in the string

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
Ask a Question
Discussion stats
  • 7 replies
  • 160 views
  • 0 likes
  • 5 in conversation