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?
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)));
@Tom,
Thank you, that is what I want, thank you very much for your priceless helps. They were very useful codes 🙂
%Let Variables=Variable1 Variable2 Variable3 Variable4 Variable5; %let PVariables=%sysfunc(prxchange(s/(\w+)/P\1/,-1,&Variables)); %put &PVariables;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.