BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
turcay
Lapis Lazuli | Level 10

@slchen,

 

Thank you very much, this is the first time for me heard PrxChange function. However, when I change "Variables" macro variable as below, it doesn't bring my desired output,

 

%Let Variables=Variable1 Column2 Variable3 Column4 Variable5;
/*Slchen*/
Data Want;
VariablesP=PrxChange('s/(\S+)/P$1/',-1,"&Variables");
Run;

It should bring -> PVar is PVariable1 PColumn2 PVariable3 PColumn4 PVariable5

 

Can you help me, please?

Cynthia_sas
SAS Super FREQ
Hi, Sichen's code is working correctly. You have to do a PROC PRINT data=WANT; to see that his PRXChange is working correctly. His code is not making a macro variable. It is making a data set called WANT with one column called VARIABLESP. If you want a macro variable from his code, you have to use CALL SYMPUT or CALL SYMPUTX to make a macro variable from his VariablesP.

cynthia
Tom
Super User Tom
Super User

You don't want to use CATX(), you want to use TRANWRD().  In general there is not much use for the CAT... function in macro code.

 

If you want to add the prefix P to every value in a space delimited list then just prefix the first word and change the delimites to include the prefix for the following words.

 

%Let Variables=Variable1 Variable2 Variable3 Variable4 Variable5;
%let newlist=P%sysfunc(tranwrd(&variables,%str( ),%str( P)));

You probably will also want to make sure your list is neat and does not have multiple spaces between words. So add this line before the other. 

%Let Variables=%sysfunc(compbl(&variables));

Or nest the call to COMPBL() into the call to TRANWRD().

%let newlist=P%sysfunc(tranwrd(%sysfunc(compbl(&variables)),%str( ),%str( P)));
turcay
Lapis Lazuli | Level 10

@Tom,

 

Thank you, that is what I want, thank you very much for your priceless helps. They were very useful codes 🙂

 

 

Ksharp
Super User
%Let Variables=Variable1 Variable2 Variable3 Variable4 Variable5;
%let PVariables=%sysfunc(prxchange(s/(\w+)/P\1/,-1,&Variables));

%put &PVariables;



sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 19 replies
  • 7035 views
  • 14 likes
  • 8 in conversation