How do you create a new variable based on conditional logic in a DATA step?

Prepare effectively for the SAS Programming Certification Exam. Access flashcards and multiple choice questions, with hints and detailed explanations. Ace your exam confidently!

Creating a new variable based on conditional logic in a DATA step is effectively achieved using IF-THEN/ELSE statements. This method allows you to evaluate certain conditions and assign values to the new variable based on the outcome of those evaluations.

When using the IF-THEN statement, you can specify logical conditions that, when met, will trigger the assignment of a specific value to the new variable. The ELSE statement can then be used to define alternative values for situations where the initial condition isn't met. This flexibility is key when you want to categorize or assign values dynamically within the dataset.

For example, if you want to create a new variable that assigns a value based on the age of individuals, you could write something like:

data new_data;
    set old_data;
    if age < 18 then age_group = 'Minor';
    else age_group = 'Adult';
run;

This effectively creates a new variable age_group based on the conditional logic provided by the IF-THEN/ELSE statements.

The other techniques mentioned do not directly facilitate the creation of a new variable based on conditional logic. The SET statement is primarily used for reading in existing data from a dataset, PROC TRANSPOSE is intended for

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy