BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

Using SAS 9.4 

 

data raw.breast (where=(DIAG_PRTY_SEQ_NBR =1));
set raw.EDVISITS_BREAST;
IF DIAG_DESC = 'pain' then DIAG_DESC2 = 'Pain';
IF DIAG_DESC = 'nausea' then DIAG_DESC2 = 'Nausea'; 
run;

 

I am trying to create a new variable and use a wildcard to capture any instance where the word 'pain' is used and group it together into a single bucket 'Pain' category. My code is creating the new variable but is not pulling anything into that column. Any help would be great. Thank you!

1 ACCEPTED SOLUTION
6 REPLIES 6
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

Will this work if I need to put multiple if then statements?

novinosrin
Tourmaline | Level 20

You need to use custom defined formats if there are too many

Astounding
PROC Star

It will work, sort of.

 

First, note that you need to set a length for your new variable.  Otherwise, it will be defined as 4 characters long because the first mention of it sets it to "Pain".

 

Second, how do you propose to handle the situation if your string contains two (or more) of the words you want to search for?  You only have one new variable to use, to hold the result. 

 

Third, you probably would want to ignore upper vs. lower case.  So this might be a better approach:

 

length diag_desc2 $ 20;

if index(upcase(diag_desc), 'PAIN') then diag_desc2='Pain';

 

This will catch variations such as Pain, pain, and PAIN.

 

 

GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

I changed the length.

 

It is a priority number so it should not hit on multiple words. 

 

I did not think about upper and lowercase so that is helpful. Thank you

bobpep212
Quartz | Level 8

I would add to Kurt's solution to consider if your source could have both uppercase and lower case versions of 'pain'. If so, I'd wrap that text field with an UPCASE function and then search for 'PAIN' (or vice versa).

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 1161 views
  • 1 like
  • 5 in conversation