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.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 669 views
  • 2 likes
  • 4 in conversation