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

The dataset I'm using has an individual variable for each phecode such as "X250.12, X250.13, X250.14...." which has "TRUE" or "FALSE" depending on whether each observation (patient) has any of these diagnoses.

 

I want to create a new variable called "Diabetes" that includes all the observations that say "true" for at least one of these variables (X250.12, X250.13, X250.14...). I know there is an easier way of doing this besides what I have attempted here but I can't remember for the life of me:

 

IF X250= "TRUE" THEN Diabetes= 1;
IF X250.1= "TRUE" THEN Diabetes= 1;
IF X250.11= "TRUE" THEN Diabetes=1;

Thank you!!

 

1 ACCEPTED SOLUTION

Accepted Solutions
5 REPLIES 5
Tom
Super User Tom
Super User

X250.1 is not a valid variable NAME.

You can have a character variable with a VALUE of 'X250.1'.

abrice520
Obsidian | Level 7
The data file I received already had these variables with these names. The names are not giving me issues and everything is running correctly, I'm asking for a more efficient way of creating the new variable I am asking about.
ChrisNZ
Tourmaline | Level 20

Like this?

DIABETES = index(catt(of X250:), 'TRUE')>0;
abrice520
Obsidian | Level 7
Yes! Thank you so much!
ballardw
Super User

There are times when data supplied really needs to be cleaned up for use. I suspect this is one of the occasions.

 

First, if the variable names are actually X250.1 then you reference them incorrectly. To have any character other than letter, digit and the _ character in a SAS variable name you have to use "name literal" construction and would reference the variable that appears like that as "X250.1"n the quotes and the n immediately following tells SAS you intend to use that string as variable name.

 

Second, data with text "True" and "False" is awkward. It is better for a number of reasons to have numeric 1/0 coded values. SAS will use 1 as "True" and 0 as "False".

Then you could code such as

Diabetes = (max(list the variable names here separated by commas) = 1 );

SAS will return the result of a comparison as 1/0.

 

If you make the variable names standard SAS names such as X250_1 instead of X205.1 then the above would allow use of variable lists such as

Diabetes = ( max(of x250:)=1);

The colon after the X250 creates a variable list that would use all of the variable names starting with X250.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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