DATA Step, Macro, Functions and more

Use string without resolving macro

Reply
Contributor
Posts: 71

Use string without resolving macro

Hi,

 

I have a conditional clause in my code which looks like below:-

 if lowcase(compress(tt)) =: 'procprinttoprint="&protpath'

Now, I want to use this string as it is for comparison without resolving the macro variable "protpath" but its not letting me do so. Please help!

Super User
Posts: 19,815

Re: Use string without resolving macro

If you enclose it in single quotes you should be fine. 

 

Your code includes one double quote but not the other? Is that a copy/paste error or the forum messing things up? Or what you want your code to look like. 

 

 if lowcase(compress(tt)) =: 'procprinttoprint="&protpath'

Please explain how it's not working, preferably with the log with the MPRINT option on. 

Contributor
Posts: 71

Re: Use string without resolving macro

[ Edited ]

Hi Reeza,

 

I want to match a particular line from the file having content like so

 

proc printto print = "&protpath/outlist/Programname.lst"
              log = "&protpath/outlog/Programname.log" new;
run;

So, to match the first line exactly I am using 

 if lowcase(compress(tt)) =: 'procprinttoprint="&protpath'

since the rest of the below string is not fixed and I want to use it as it is without any macro resolution. Also, I tried using %nrstr but since its SCL code its not working in my data set.

procprinttoprint="&protpath 

 

Super User
Posts: 19,815

Re: Use string without resolving macro

It works fine for me. You have some other issue besides the quotation marks or macro variable not resolving. Check your log and logic. 

 

%let protopath = Stupid;
data have;
length tt $100.;
tt='proc printto print = "&protpath/outlist/Programname.lst"
              log = "&protpath/outlog/Programname.log" new;';
if lowcase(compress(tt)) =: 'procprinttoprint="&protpath' then put "Pass";
else put "Fail";
run;
Super User
Posts: 7,805

Re: Use string without resolving macro

Where's your problem?

data _null_;
tt = 'proc printto print = "&protpath/outlist/Programname.lst"';
if lowcase(compress(tt)) =: 'procprinttoprint="&protpath'
then put 'yes';
else put 'no';
run;

gives me this log:

16         data _null_;
17         tt = 'proc printto print = "&protpath/outlist/Programname.lst"';
18         if lowcase(compress(tt)) =: 'procprinttoprint="&protpath'
19         then put 'yes';
20         else put 'no';
21         run;

yes
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

So the condition works.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 71

Re: Use string without resolving macro

Posted in reply to KurtBremser

My code is a mix of SCL and Base Programming because of which the macro variable "protpath" was getting resolved in the code.

Using the below snippet resolved the problem:

 

%let match_string= %nrstr(procprinttoprint=%"&protpath/outlist/); 

 

Thanks so much everyone for your input. This was urgently required.

Super User
Super User
Posts: 7,962

Re: Use string without resolving macro

I agree with @Reeza, enclosing a macro variable in single quotes means that the macro pre-processor will not pick the & up as a macro reference and ignore it.  However, it does look like your processing code in another program, i.e. reading some SAS code in a processing it.  Not a very good way of doing things, have seen this approach several times and it is symptomatic of not following software development lifecycle processes.  I.e. you have code and are now trying to get documentation or validation from it.  This is not good for two reasons.  Firstly anything you do after the event cannot be construed as proper documentation or validation.  Secondly actually processing code is quite complicated.  

Ask a Question
Discussion stats
  • 6 replies
  • 288 views
  • 1 like
  • 4 in conversation