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.

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 3 replies
  • 3831 views
  • 2 likes
  • 3 in conversation