BookmarkSubscribeRSS Feed
petlove
Obsidian | Level 7

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.

 

4 REPLIES 4
novinosrin
Tourmaline | Level 20

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

PaigeMiller
Diamond | Level 26

UNTESTED CODE

 

data want;
    set have;
    if find(var1,'IESTRESC')>0 then var1='IESTRESC';
run;
--
Paige Miller
ballardw
Super User

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?

ChrisNZ
Tourmaline | Level 20

Like this?

data WANT;
  set HAVE;
  if find(VAR1,VAR2,'t') then VAR1=VAR2;
run;

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 4 replies
  • 2136 views
  • 0 likes
  • 5 in conversation