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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1342 views
  • 0 likes
  • 5 in conversation