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.
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));
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!
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.