Hi Everyone,
I have a start variable having value 1.
When value =1, I want to run the below 2 data steps.
Of course, I can run the whole process on every single record but it is not optimal.
I appreciate it if you could help me.
HHC
data have;
input start order value;
datalines;
0 1 5
0 2 2
0 3 4
0 4 4
0 5 5
0 6 2
0 7 7
0 8 1
0 9 13
0 1 10 5
0 1 56
0 2 26
0 3 46
0 4 46
0 5 18
0 6 58
0 7 8
0 8 2
0 9 100
1 10 5
;
run;
IF START=1 THEN DO THE FOLLOWING PROCESS
data want;
set have;
drop aa1-aa10;
array a{0:9} aa1-aa10;
retain aa:;
pct_60=largest((10-10*60/100+1),of a{*});
pct_70=largest((10-10*70/100+1),of a{*});
pct_80=largest((10-10*80/100+1),of a{*});
pct_90=largest((10-10*90/100+1),of a{*});
a{mod(_n_,10)}=value;
run;
data want; set want;
drop pct_25-pct_100 ;
if value>=pct_90 then ROC_rank=5;
else if value>=pct_80 then ROC_rank=4;
else if value>=pct_70 then ROC_rank=3;
else if value>=pct_60 then ROC_rank=1.5;
else ROC_rank=0.1;
run;
I'm not certain I understand fully. It seems like you want to compare value with the preceeding 10 values and set ROC_rank based on the ranking of value relative to the set of 10. Furthermore, you want output only for cases where start=1. The role of variable order is undefined. This would do that:
data want;
set have;
array a{0:9} _temporary_;
if start and nmiss(of a{*})=0 then do;
if value>=largest(1,of a{*}) then ROC_rank=5;
else if value>=largest(2,of a{*}) then ROC_rank=4;
else if value>=largest(3,of a{*}) then ROC_rank=3;
else if value>=largest(4,of a{*}) then ROC_rank=1.5;
else ROC_rank=0.1;
output;
end;
a{mod(_n_,10)}=value;
run;
Your example code generates an error: it is interrupted because of looping. What is it intended to do?
Sorry for not deleting the IF statement.
Here is the clean one.
Thank you for helping, PGStats.
HHC
data have;
input start order value;
datalines;
0 1 5
0 2 2
0 3 4
0 4 4
0 5 5
0 6 2
0 7 7
0 8 1
0 9 13
0 1 10 5
0 1 56
0 2 26
0 3 46
0 4 46
0 5 18
0 6 58
0 7 8
0 8 2
0 9 100
1 10 5
;
run;
*IF START=1 THEN DO THE FOLLOWING PROCESS;
data want;
set have;
drop aa1-aa10;
array a{0:9} aa1-aa10;
retain aa:;
pct_60=largest((10-10*60/100+1),of a{*});
pct_70=largest((10-10*70/100+1),of a{*});
pct_80=largest((10-10*80/100+1),of a{*});
pct_90=largest((10-10*90/100+1),of a{*});
a{mod(_n_,10)}=value;
run;
data want; set want;
drop pct_25-pct_100 ;
if value>=pct_90 then ROC_rank=5;
else if value>=pct_80 then ROC_rank=4;
else if value>=pct_70 then ROC_rank=3;
else if value>=pct_60 then ROC_rank=1.5;
else ROC_rank=0.1;
run;
I'm not certain I understand fully. It seems like you want to compare value with the preceeding 10 values and set ROC_rank based on the ranking of value relative to the set of 10. Furthermore, you want output only for cases where start=1. The role of variable order is undefined. This would do that:
data want;
set have;
array a{0:9} _temporary_;
if start and nmiss(of a{*})=0 then do;
if value>=largest(1,of a{*}) then ROC_rank=5;
else if value>=largest(2,of a{*}) then ROC_rank=4;
else if value>=largest(3,of a{*}) then ROC_rank=3;
else if value>=largest(4,of a{*}) then ROC_rank=1.5;
else ROC_rank=0.1;
output;
end;
a{mod(_n_,10)}=value;
run;
Hi PGStats,
Your code work perfectly in this case. And yes, I only need to output record with start=1.
However, I did not foresee that it can be done in only 1 step.
And my code to run when start=1 involve few other steps.
So it is the best for me if I can put the MAIN analysis section within some kind IF as below.
It will help me alot for other applicaiton as well.
Thank you so much.
HHC
IF start=1 then do;
data want;
set have;
drop aa1-aa10;
array a{0:9} aa1-aa10;
retain aa:;
pct_60=largest((10-10*60/100+1),of a{*});
pct_70=largest((10-10*70/100+1),of a{*});
pct_80=largest((10-10*80/100+1),of a{*});
pct_90=largest((10-10*90/100+1),of a{*});
a{mod(_n_,10)}=value;
run;
END;
data want; set want;
drop pct_25-pct_100 ;
if value>=pct_90 then ROC_rank=5;
else if value>=pct_80 then ROC_rank=4;
else if value>=pct_70 then ROC_rank=3;
else if value>=pct_60 then ROC_rank=1.5;
else ROC_rank=0.1;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.