BookmarkSubscribeRSS Feed
Aditi24
Obsidian | Level 7

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!

6 REPLIES 6
Reeza
Super User

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. 

Aditi24
Obsidian | Level 7

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 

 

Reeza
Super User

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;
Kurt_Bremser
Super User

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.

Aditi24
Obsidian | Level 7

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.  

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1538 views
  • 1 like
  • 4 in conversation