BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
michtka
Fluorite | Level 6

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.

1 ACCEPTED SOLUTION

Accepted Solutions
michtka
Fluorite | Level 6

...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;

View solution in original post

1 REPLY 1
michtka
Fluorite | Level 6

...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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1329 views
  • 0 likes
  • 1 in conversation