BookmarkSubscribeRSS Feed
ari2495
Obsidian | Level 7
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

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Your code looks fine. The problem is likely in the initial_dataset data.

mkeintz
PROC Star

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"

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
SASKiwi
PROC Star

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.

 

Tom
Super User Tom
Super User

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?

ari2495
Obsidian | Level 7
I really have to thank you all for all
Your answers; I detected that the problem was with the last “then do”; simply eliminating it the code worked well again. Many thanks!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 356 views
  • 8 likes
  • 5 in conversation