BookmarkSubscribeRSS Feed
sas_user124
Calcite | Level 5

Hi, I have a treatment variable with categories surgery, medication, other. Each person's treatment in the column looks like 'surgery+other' 'other+medication' etc. and I want to create individual columns for surgery, medication, and other that will mark the patient as having each type of surgery. How do i code this?

1 REPLY 1
ballardw
Super User

One way is to search a text field for key words and if present assign a value to the other value. If you want to "count" there are choices of what values to assign.

If I understand your need and this were my project I might do something like:

data want;
   set have;
   surgery = (find(treatment,'surgery','i')>0);
   medication = (find(treatment,'medication','i')>0);
   other =  (find(treatment,'other','i')>0);
run;

This assumes that your variable name is Treatment, since you weren't explicit about that.

The code will assign a value of 1 to the variables Surgery, Medication or Other if the text in quotes appears in the value and 0 otherwise. The 'i' in the parameters to the find function tell SAS to ignore case, so if the word sometimes appears as "Other" "other" "OTHER" or other case combinations they are set. If the word appears twice (surgery+other+surgery for example surgery is only assigned a value of 1).

The 1/0 coding is very flexible as the SUM of the variable is the count  of times the word appears at least once per observation. The Mean of the variable would be the percent of ones (.75 = 75% for example).

 

Other statistics available in reports could tell if if every observation for a patient (or other grouping variable) has some characteristic. MAX=1 at least one observation had the value in the treatment Max=0 means none, Range=0 means all values the same (all observations has surgery or none id).

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 164 views
  • 0 likes
  • 2 in conversation