data final_dataset;
set initial_dataset;
length variable $50.;
if cond not in (0) then do;
variable_1="S2";
variable="xxx";
end;
else if cond_1 > 30 then do;
variable_1="S2";
variable="xxy";
end;
else if cond_2 > soglia then do;
variable_1 ="S2";
variable="xyy";
end;
else if cond_3="Stage 1" then do;
variable="yyy";
end;
run;
the problem is that, when i print the result, the new column i created named "variable" is empty. i cannot understand why
Your code looks fine. The problem is likely in the initial_dataset data.
Your logical structure is equivalent to
if A then create results ;
else if B then create results;
else if C then create results;
else if D then create results;
Even though you are using "else if" syntax, the set of observations that would satisfy the above would be this intersection:
A ∩ B ∩ C ∩ D
If your log shows no errors messages, yet you have no observation with values for the result variables, then every obs in your dataset falls outside the above intersection. So, by De Morgan's Laws all of your observations fall in the complement, characterized by
(not A) ∪ (not B) ∪ (not C) ∪ (not D)
(where ∪ is the union set operator and is equivalent to and in any subsetting syntax in SAS.
Now, in your case
condition A <==> cond not in (0)
condition B <==> cond_1 > 30
condition C <==> cond_2>soglia
condition D <==> cond_3="Stage 1"
which means that all of your observations must have
cond in (0) and
cond_1<=30 and
cond_2<=soglia and
cond_3 ^="Stage 1"
PROC FREQ will help you find what is wrong with your logic, given there are no syntax errors in your code:
proc freq data = initial_dataset;
table cond * cond_1 * cond_2 * cond_3 / missing list;
run;
Examine the combination of values shown in the output.
Did SAS print any notes about uninitialized variables? Do you really have the variables you are referencing:
cond cond_1 cond_2 soglia cond_3
If there are such notes then fix issue first.
Otherwise look at the actual values of the variables you are testing.
For example try running this PROC FREQ and see what it tells you.
proc freq data= initial_dataset;
tables cond*cond_1*cond_2*soglia*cond_3 / list missing;
run;
Are there any rows output that meet your conditions?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.