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

Hi all SAS Users,

 

Today I want to have the output that Percent is ranked descending.

My code is

ods noproctitle;
title' Categories of Reported Species ';
proc freq data=pg1.np_species;
tables Category/ nocum;

 

ResoluteCarbon_0-1617222907460.png

 

From what I learnt, if I want to have Frequency as descending, I can use option order=freq on proc freq data statement, if I want the order of Category as alphabet ascending, I just add nothing. But when I tried to rank the percent by descending, I cannot do that. I am wondering is there any option to do have the result that Percent will be ranked as descending without creating another proc sort datastep?

 

Thanks in advance.

 

P/S: What I tried are:

34         ods noproctitle;
35         title' Categories of Reported Species ';
36         proc freq data=pg1.np_species order=percent;
                                               _______
                                               22
                                               76
ERROR 22-322: Syntax error, expecting one of the following: DATA, FORMATTED, FREQ, INTERNAL.  
ERROR 76-322: Syntax error, statement will be ignored.
34         ods noproctitle;
35         title' Categories of Reported Species ';


36         proc freq data=pg1.np_species;
37         tables descending Category/ nocum;
ERROR: Variable DESCENDING not found.

And could you please let me know why these two approaches are wrong?

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
For a table with only a single variable, the order of highest frequency is the same order as highest percent since the denominator is consistent across all rows.

So use ORDER=FREQ will give you the desired results.

AFAIK, there isn't another way to control the order besides SORT and ORDER=DATA to use the data order.

View solution in original post

3 REPLIES 3
Astounding
PROC Star

According to the documentation,  you would use:

proc freq data=pg1.np_species order=freq;
ResoluteCarbon
Obsidian | Level 7

Hi @Astounding 

But this option only works with Frequency variable, not Percentage variable.

Thanks.

Reeza
Super User
For a table with only a single variable, the order of highest frequency is the same order as highest percent since the denominator is consistent across all rows.

So use ORDER=FREQ will give you the desired results.

AFAIK, there isn't another way to control the order besides SORT and ORDER=DATA to use the data order.
How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 5382 views
  • 2 likes
  • 3 in conversation