SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
ute
Calcite | Level 5 ute
Calcite | Level 5

I am trying to write a macro that puts a prefix inside all quoted strings in a list. It does work, but throws Note 49-169 for all prefix that seem not to make sense to SAS.

%macro prefixstrings(stringlist, prefix);
  %sysfunc(prxchange(s/\'(\w+)/'&prefix$1/,-1,&stringlist))
%mend;

%put %prefixstrings(unquoted test 'quoted test', x);
/* no complaints because apparently '...'x is detected as having a meaning */
%put %prefixstrings(unquoted test 'quoted test', A);
/* NOTE 49-169 ... :-(  */

Is there an easy workaround to avoid this? Putting a blank before &prefix is no option since the result is undesired.

2 REPLIES 2
s_lassen
Meteorite | Level 14

Put the initial quote into a look-behind assertion, like this:

%macro prefixstrings(stringlist, prefix);
  %sysfunc(prxchange(s/(?<=%str(%'))(\w+)/&prefix$1/,-1,&stringlist))
%mend;
ute
Calcite | Level 5 ute
Calcite | Level 5
Nice workaround, thank you 🙂

I secretly hoped it would be possible to forbid SAS macro compiler to look too deeply into the code it is meant to produce, but this one does the current job, definitely.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 2 replies
  • 723 views
  • 1 like
  • 2 in conversation