Hi all,
I am looking for way to extract the specific word from character variables where specific word is present in other variable.
For example:
one dataset has var1 variable and other dataset has var2 variables:
1. var1: it has value "Missing variable: IESTRESC "
2. var2: it has value "IESTRESC"
Now, I want to remove all other text and just keep "IESTRESC" in var1 variable. how should it be done?
NOTE: position of "IESTRESC" can be anywhere in var1.
Thank you.
If you could present a nice comprehensive data sample of your dataset, that would help the community better
Meaning sample of both your datasets with values like 5 records each
UNTESTED CODE
data want;
set have;
if find(var1,'IESTRESC')>0 then var1='IESTRESC';
run;
Only one value? Or a bunch of values that you need to examine each value for possible occurrence in the variable?
If you have more than one value to search for is it possible that two or more may occur in the long value? If so what would the result look like then?
Would that searched for value possibly occur as part of other words?
Is the search value going to be case sensitive?
And are there any spelling errors such that you have IESTRSC instead of IESTRESC that also need to match?
Like this?
data WANT;
set HAVE;
if find(VAR1,VAR2,'t') then VAR1=VAR2;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.