Hi,
I am trying to create a new variable based on a re-ordered variable that includes groups 1,2,3,4 only (not group 5). I have reordered the variable below, but cannot figure out how to create a new variable that includes groups 1,2,3,4. I want to then work with this new variable to run the rest of my coding...
data a;
if class = 1 then class_new = 1;
if class = 2 then class_new = 2;
if class = 3 then class_new = 3;
if class = 4 then class_new = 5;
if class = 5 then class_new = 4;
run;
data a;
if class_new = 1,2,3,4 (is this correct?) then class_new_final= "final classes";
run;
@katez01 wrote:
data a;
if class_new = 1,2,3,4 (is this correct?) then class_new_final= "final classes";
run;
I think you want
if class_new in (1,2,3,4) then ...
but I really don't understand the part
then class_new_final= "final classes";
but maybe that doesn't really matter here.
Of course you could simplify the code even further by using working with the original variable named CLASS
if class in (1,2,3,5) then ...
and then you don't need all those IF statements.
Your data steps probably need a SET statement or an INPUT statement.
Presumably you already have a data set that contains CLASS. To use that data set, you need to use a SET statement. For example, if the name of the data set that contains CLASS is A, you need:
data new;
set a;
... whatever changes you want to make, such as creating class_final ...;
run;
If you use this statement instead, you will destroy your existing data set:
data a;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.