proc freq data=have order=freq ;
tables var1/list missing out=var1_freq;
run;
The proc freq above outputs by descending order of frequency of var1.
I need the opposite, which is by ascending order.
And the output only gives the frequency and percentage. How can I get the cumulative freq and cumulative percentage as well? These two should vary depending on how you order the var1.
Editor's Note: The documentation for PROC FREQ defines the ORDER=FREQ option as the descending frequency count. Unfortunately, there is not an option to make this ascending. Other procedures, such as PROC REPORT, define ORDER=FREQ as the ascending frequency count. However, given that the cumulative statistics are also desired, the PROC FREQ and DATA Step solution provided by @ballardw is best for this case.
Example input data and desired output will go a long way toward reducing suggestions that do not answer non-specified requirements. Your first post is change the order. And suggestions follow. After that you request that the cumulative totals be reordered, not in the initial post.
And when you start getting into non-standard behaviors then you get to do a little more work. Not much. Please see:
proc freq data=sashelp.class noprint; tables age / out=agefreq; run; proc sort data=agefreq; by count; run; data want; set agefreq;
cumcount + count; cumpercent + percent; run;
Editor's Note: The documentation for PROC FREQ defines the ORDER=FREQ option as the descending frequency count. Unfortunately, there is not an option to make this ascending. Other procedures, such as PROC REPORT, define ORDER=FREQ as the ascending frequency count. However, given that the cumulative statistics are also desired, the PROC FREQ and DATA Step solution provided by @ballardw is best for this case.
Example input data and desired output will go a long way toward reducing suggestions that do not answer non-specified requirements. Your first post is change the order. And suggestions follow. After that you request that the cumulative totals be reordered, not in the initial post.
And when you start getting into non-standard behaviors then you get to do a little more work. Not much. Please see:
proc freq data=sashelp.class noprint; tables age / out=agefreq; run; proc sort data=agefreq; by count; run; data want; set agefreq;
cumcount + count; cumpercent + percent; run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.