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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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