Hello,
I realized in my dataset that some of my if/then were not taken , but I can't understand why, I hope you could enlighten me, excuse me in advance for this long messy code.
data logique;
set propre;
if Status='Executed' then do;
if missing(volunteer_execution) then volunteer_execution='E';
died='N';
suicide='N';
released='N';
commuted='N';
reduction_de_peine='N';
current_sentence='DR';
if missing(exonerated)=1 then exonerated='E';
if missing(resentenced)=1 then resentenced='E';
end;
else if Status='On Death Row' then do;
volunteer_execution='N';
died='N';
released='N';
suicide='N';
commuted='N';
reduction_de_peine='N';
current_sentence='DR';
exonerated='N';
if missing(resentenced)=1 then resentenced='E';
end;
else if Status='Not Currently On Death Row' then do;
released='N';
exonerated='N';
volunteer_execution='N';
if missing(died)=1 then died='E';
if missing(suicide)=1 then suicide='E';
if missing(commuted)=1 then commuted='E';
if missing(resentenced)=1 then resentenced='E';
if missing(current_sentence)=1 then current_sentence='DR';
end;
else if Status='Outside' then do;
died='N';
suicide='N';
volunteer_execution='N';
if missing(commuted)=1 then commuted='E';
if (exonerated='Y')+(resentenced^='Y')=2 then resentenced='N';
if exonerated^='Y' then resentenced='Y';
if missing(current_sentence)=1 then current_sentence='E';
if exonerated^='Y' then exonerated='E';
if exonerated='Y' then reduction_de_peine='L';
if missing(resentenced)=1 then resentenced='E';
end;
run;
PART 2
data lib.final_table;
set logique;
if commuted='Y' then reduction_de_peine='Y';
if resentenced^='Y' and current_sentence not in(' ','DR') then resentenced='Y';
if (resentenced='Y')+(current_sentence not in('DR',' '))=2 then reduction_de_peine='Y';
if reduction_de_peine='Y' then resentenced='Y';
if Status='Not Currently On Death Row' then do;/*Nous y voila*/
if (resentenced^='Y')+(died='Y')+(current_sentence='E')=3 then current_sentence='DR';
if (reduction_de_peine^='Y') and died^='Y' then do;
released='Y';
exonerated='Y';
end;
if (released='Y')+(reduction_de_peine^='Y')=2 then do;
exonerated='Y';
end;
if (released='Y')+(exonerated^='Y') then do;
reduction_de_peine='Y';
resentenced='Y';
end;
if (released='Y')+(reduction_de_peine^='N')+(current_sentence='E')=3 then current_sentence='DR';
if (reduction_de_peine='Y')+missing(died)=2 then do;
died='N';
suicide='N';
end;
if (resentenced='E')+(died='Y')=2 then resentenced='N';
end;
if (resentenced='Y')+(Status in ('On Death Row','Executed'))=2 then reduction_de_peine='N';
if suicide='N' then died='N';
if (reduction_de_peine='Y')+(exonerated='E')=2 then exonerated='N';
if missing(volunteer_execution)=1 then volunteer_execution='E';
/* je renvoi les gens released ou exonerated en Outside*/
if released='Y' or exonerated='Y' then Status='Outside';
if exonerated='Y' then released='I';
format volunteer_execution died suicide commuted exonerated resentenced released reduction_de_peine $modal.;
run;
ps: Beyond the real problem, if you have an idea of code optimization I am listening!
@oussama2 wrote:
I realized in my dataset that some of my if/then were not taken , but I can't understand why, I hope you could enlighten me, excuse me in advance for this long messy code.
Be specific. Show us the exact parts of the code that you think should be executing, that are not executing (make them appear in red text, for example).
Show us a portion of the data as SAS data step code (instructions). Show us the desired output from this portion of the data.
@oussama2 wrote:
There are several things that are not taken into account, for example for Status='Outside' I specified died='N' but when I print the final result I see died='E' while I have not made any change in the rest of the code, and there are several problems of this type.
This snippet of code does not appear in the code you provided. So again, I ask that you highlight your code in red to indicate what parts of the code you think are not executing.
Also, do not ignore my request to see a portion of the data, and do not ignore the instructions I gave for providing the data. It's really really difficult to figure these things out without the additional information that I requested.
Please post formatted code using the running-man icon and some data that we have something to work with.
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.