Statistical Analysis System (SAS) Programming Certification Practice Exam 2025 – The All-in-One Guide to Master Your Certification!

Question: 1 / 400

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

By using the SET statement to input data

By using the IF-THEN/ELSE statements

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:

```sas

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

Get further explanation with Examzify DeepDiveBeta

By using PROC TRANSPOSE to restructure data

By implementing the MERGE statement

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy