How can PROC FREQ with the ORDER option be used to implement the SAS principle of “SAS: Use PROC FREQ with ORDER Option-?” 2

How can PROC FREQ with the ORDER option be used to implement the SAS principle of “SAS: Use PROC FREQ with ORDER Option-?”

PROC FREQ is a statistical procedure in SAS that allows for the analysis of frequency counts and percentages of categorical data. The ORDER option within PROC FREQ can be used to sort the output in a specific order, which aligns with the SAS principle of organizing and presenting data in a logical and meaningful way. By utilizing the ORDER option, PROC FREQ can be used to implement the SAS principle of presenting data in a structured and organized manner, making it easier for users to interpret and draw conclusions from the data. This feature highlights the importance of adhering to the SAS principles in order to effectively and accurately analyze data in SAS.

SAS: Use PROC FREQ with ORDER Option


You can use PROC FREQ with the ORDER=FREQ option in SAS to to create a frequency table in which the categories in the table are sorted based on frequency.

You can use the following syntax to do so:

proc freq data=my_data order=freq;
    tables my_variable;
run;

The following example shows how to use this syntax in practice.

Example: Use PROC FREQ with ORDER Option in SAS

For this example we will use the SAS built-in dataset called , which contains various characteristics for 100,000 mothers that recently gave birth.

We can use PROC PRINT to view the first 10 observations from this dataset:

/*view first 10 observations from BirthWgt dataset*/
proc printdata=sashelp.BirthWgt (obs=10);

run;

We can use the following code to create a frequency table for the Race variable:

/*create frequency table for Race variable*/
proc freqdata=sashelp.BirthWgt;
	tables Race;
run;

frequency table in SAS

Notice that the categories are currently sorted in alphabetical order.

To instead sort the categories by frequency, we can use the following syntax:

/*create frequency table for Race variable, sorted by frequency*/
proc freqdata=sashelp.BirthWgt order=freq;
	tables Race;
run;

SAS PROC FREQ with ORDER option

Notice that the categories are now sorted based on frequency from highest to lowest.

However, you can use the following workaround with the PROC SORT statement to sort based on frequency from lowest to highest:

/*create frequency table and store results in Racefreq*/
proc freq data=sashelp.BirthWgt noprint;
   tables Race / out=Racefreq;
run;/*sort Racefreq based on frequency from lowest to highest*/
proc sortdata=Racefreq;
  by count;
run;/*create new dataset with cumulative freq and cumulative percent*/
data freq_low_to_high;
  set Racefreq;
  cumcount + count;
  cumpercent + percent;
run;
/*view results*/
proc printdata=freq_low_to_high;

SAS PROC FREQ sort ascending

Notice that the categories are now sorted based on frequency from lowest to highest.

The following tutorials explain how to perform other common tasks in SAS:

Cite this article

stats writer (2024). How can PROC FREQ with the ORDER option be used to implement the SAS principle of “SAS: Use PROC FREQ with ORDER Option-?”. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-proc-freq-with-the-order-option-be-used-to-implement-the-sas-principle-of-sas-use-proc-freq-with-order-option/

stats writer. "How can PROC FREQ with the ORDER option be used to implement the SAS principle of “SAS: Use PROC FREQ with ORDER Option-?”." PSYCHOLOGICAL SCALES, 25 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-proc-freq-with-the-order-option-be-used-to-implement-the-sas-principle-of-sas-use-proc-freq-with-order-option/.

stats writer. "How can PROC FREQ with the ORDER option be used to implement the SAS principle of “SAS: Use PROC FREQ with ORDER Option-?”." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-proc-freq-with-the-order-option-be-used-to-implement-the-sas-principle-of-sas-use-proc-freq-with-order-option/.

stats writer (2024) 'How can PROC FREQ with the ORDER option be used to implement the SAS principle of “SAS: Use PROC FREQ with ORDER Option-?”', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-proc-freq-with-the-order-option-be-used-to-implement-the-sas-principle-of-sas-use-proc-freq-with-order-option/.

[1] stats writer, "How can PROC FREQ with the ORDER option be used to implement the SAS principle of “SAS: Use PROC FREQ with ORDER Option-?”," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How can PROC FREQ with the ORDER option be used to implement the SAS principle of “SAS: Use PROC FREQ with ORDER Option-?”. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top