Hi all,
I need to sorting out my final dataset by descending frequency in aesoc and aept, by I do not know how:
I've go the next code:
data have;
length aesoc aept $10.;
input aesoc aept;
datalines;
head factor1
head factor1
head factor2
mouth facto3
mouth factor4
liver factor 5
liver factor6
liver factor6
liver factor 6
;
run;
proc sql noprint;
create table have1 as
select count(aesoc) as nsoc,aesoc
from have
group by aesoc
order by aesoc;
quit;
proc sql noprint;
create table have2 as
select count(aept) as npt,aesoc,aept
from have
group by aesoc,aept
order by aesoc,aept;
quit;
proc sql noprint;
create table have3 as
select a.*, b.npt,b.aept
from have1 as a left join have2 as b
on a.aesoc=b.aesoc;
quit;
data final (drop=aesoc aept);
set have3;
by aesoc aept;
if first.aesoc then do;
trt=put(nsoc,3.);
aeterm=upcase(aesoc);
output;
end;
if first.aept then do;
trt=put(npt,3.);
aeterm=aept;
output;
end;
run;
proc print data=final noobs ;
run;
This is the result I get ***, but as you can see I need to sorting it in terms of descending frequency, somethig like : LIVER first (factor,factor6), HEAD(factor1,factor2) and finally MOUTH (factor3 factor4)
***** (this is not sorting out by descendig frequency, it has been sorting out by AESOC, AEPT)
nsoc npt trt aeterm
3 2 3 HEAD
3 2 2 factor1
3 1 1 factor2
4 2 4 LIVER
4 2 2 factor
4 2 2 factor6
2 1 2 MOUTH
2 1 1 facto3
2 1 1 factor4
Thanks in advance,
V.
...I found the solution...Thanks.
......
proc sort data=have3;by descending nsoc descending npt;run; *sorting by descending frequency;
data final (drop=aesoc aept);
set have3;
by aesoc aept notsorted; ****to keep the code intact;
if first.aesoc then do;
trt=put(nsoc,3.);
aeterm=upcase(aesoc);
output;
end;
if first.aept then do;
trt=put(npt,3.);
aeterm=aept;
output;
end;
run;
...I found the solution...Thanks.
......
proc sort data=have3;by descending nsoc descending npt;run; *sorting by descending frequency;
data final (drop=aesoc aept);
set have3;
by aesoc aept notsorted; ****to keep the code intact;
if first.aesoc then do;
trt=put(nsoc,3.);
aeterm=upcase(aesoc);
output;
end;
if first.aept then do;
trt=put(npt,3.);
aeterm=aept;
output;
end;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: