BookmarkSubscribeRSS Feed
keen_sas
Quartz | Level 8

Hi All,

I have the below dataset, need to replace the values in target variable with Replace variable. Its working fine with tranwrd , but i am unable to do using PRXCHANGE and PRX parse as i am missing how to PARSE the Target variable values in PRXPARSE

Source target  replace Output
Vegetables are apples and oranges vegetables Fruits Fruits are apples and oranges
Sugars are Fruct and Fructose fruct GLUC Sugars are GLUC and Fructose
Labtest and Labtestcd are same Labtestcd Lab.Labtestcd Labtest and lab.labtestcd are same

 

data aa;
set abc;
new=tranwrd(source,target,replacement) ;
neew = PrxChange('s/\b(Vegetables)\b/Fruits/i' , -1 , strip(source));;
run ;

 

In the above example i am replacing fruits with vegetables, but i am having huge dataset and i have to replace all the target variable with replace variable. Target variable can consists of  combination of letters , numbers and special characters , but i have to replace them with replace variable. How do i parse the TARGET variable values to use them in PRXCHANGE .

Any sample code with little explanation on how to use PRXPARSE and PRXCHANGE replace in dataset. Individually it can be done , but with different combinations its causing issue.

1 REPLY 1
andreas_lds
Jade | Level 19

Unfortunately you have not provided data in usable form, so i can't post tested code:

expression = cats('s/\b(', target, ')\b/', replace, '/i');
neew = prxchange(expression, -1, strip(source));

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1 reply
  • 1049 views
  • 0 likes
  • 2 in conversation