BookmarkSubscribeRSS Feed
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.


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

Diamond | Level 26



data want;
    set have;
    if find(var1,'IESTRESC')>0 then var1='IESTRESC';
Paige Miller
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?

Tourmaline | Level 20

Like this?

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



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
  • 5 in conversation