Solved
Contributor
Posts: 58

# Create a new variable based on the value of another variable

[ Edited ]

I want to create a new variable based on specidif conditions. If the conditions are met, I want that new variable to carry the value that is in a different variable:

Example

IF (ROLE_IN_REFERRAL = 'x' or
ROLE_IN_REFERRAL = 'y' or
ROLE_IN_REFERRAL = 'z')
THEN AGE_AT_RFRL_CHLD =

use the value(in this case the age)  that is in variable: (age_at_referral)
ELSE AGE_AT_RFRL_CHLD = . ; run;

Accepted Solutions
Solution
‎06-25-2017 10:04 PM
PROC Star
Posts: 326

## Re: Create a new variable based on the value of another variable

IF ROLE_IN_REFERRAL in( 'x', 'y' , 'z')
THEN AGE_AT_RFRL_CHLD = age_at_referral;
ELSE AGE_AT_RFRL_CHLD = . ;

All Replies
PROC Star
Posts: 1,167

## Re: Create a new variable based on the value of another variable

This is pretty straightforward, but two questions first:

1. Which SAS environment are you trying to do this in (Base SAS, Enterprise Guide, DI Studio, ...).

2. It looks like ROLE_IN_REFERRAL is character, and age_at_referral and AGE_AT_RFRL_CHILD are both numeric. Please confirm.

Tom

Contributor
Posts: 58

## Re: Create a new variable based on the value of another variable

Hi Tom

I work with SAS9.4

and yes ROLE_IN_REFERRAL is character, and age_at_referral and AGE_AT_RFRL_CHILD are both numeric

Solution
‎06-25-2017 10:04 PM
PROC Star
Posts: 326

## Re: Create a new variable based on the value of another variable

IF ROLE_IN_REFERRAL in( 'x', 'y' , 'z')
THEN AGE_AT_RFRL_CHLD = age_at_referral;
ELSE AGE_AT_RFRL_CHLD = . ;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
• 3 replies
• 168 views
• 1 like
• 3 in conversation