Whatg do you think about this one? I am wondering if I can simplify step (merge proc sql) and (proc sort) in only only an proc sql...Thanks in advance. ***sum of severities by value and intensity; proc sql noprint; create table want2 as select upcase(value) as value, intensity,nintensity,color, ncolor, sum (nintensity) as n1 from have group by value,intensity order by value, color, intensity descending; quit; **flaging priority (Severe>Moderate>Mild); data havex; set have; if upcase(intensity)="SEVERE" then flag=3; else if upcase(intensity)="MODERATE" then flag=2; else if upcase(intensity)="MILD" then flag=1; run; ***first proc sql to create the order of value in the variable label; proc sql noprint; create table want2x as select value, intensity,nintensity,color, ncolor, sum(flag) as col1 from havex group by value, color order by value, color, intensity descending; quit; ***second proc sql to create the order of color in the variable label proc sql noprint; create table want3x as select value, intensity,nintensity,color, ncolor, sum(flag) as col0 from havex group by value order by value, color, intensity descending; quit; data want3; merge want2x want3x; by value color; run; proc sort data=want3 out=want3s;by descending col0 descending col1 color descending intensity;run; **create the variable label; data want4 (keep=label value color count count2); set want3s; by descending col0 descending col1; if first.col0 then do; label=upcase(value); count+1; count2=0; output; end; if first.col1 then do; label=color; count+1; count2=1; output; end; run; **merge proc sql; proc sql noprint; create table want5 as select a.label,a.count,a.count2,b.color,b.ncolor,b.intensity,n1 from want4 as a left join want2 as b on a.label=b.value or a.color=b.color order by count,color, intensity descending; quit; ***proc sort; (I am wondering if I can include this step in the above step); Need help for this one proc sort data=want5 out=want5s nodupkey; by count descending intensity; run; Final dataset wantx; data wantx (keep=label intensity ncolor); set want5s; by count; if count2=0 then ncolor=n1; run;
... View more