How can I use PROC FREQ with a WHERE statement to apply the SAS principle of “SAS: Use PROC FREQ with WHERE Statement”? 2

How can I use PROC FREQ with a WHERE statement to apply the SAS principle of “SAS: Use PROC FREQ with WHERE Statement”?

PROC FREQ is a statistical procedure in SAS that can be used to calculate frequencies and other summary statistics for categorical data. It can be further enhanced by using a WHERE statement, which allows users to specify specific criteria for the data to be analyzed. By applying the SAS principle of “SAS: Use PROC FREQ with WHERE Statement”, users can filter their data based on certain conditions and obtain more specific and targeted results from the PROC FREQ analysis. This can be helpful in identifying patterns or trends in data and making informed decisions based on the results. Overall, using PROC FREQ with a WHERE statement can help users to effectively and efficiently apply the SAS principles of analysis and data manipulation.

SAS: Use PROC FREQ with WHERE Statement


You can use the following basic syntax to use a WHERE statement within PROC FREQ in SAS:

proc freqdata=my_data;
    where var1 ='A';
    tables var2;
run;

This particular syntax creates a frequency table for the variable called var2 but only for the rows where var1 is equal to ‘A’.

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

Example: Using Proc FREQ with WHERE Statement in SAS

Suppose we have the following dataset in SAS:

/*create dataset*/
data my_data;
    input team $ position $ points;
    datalines;
A Guard 22
A Guard 20
A Guard 30
A Forward 14
A Forward 11
B Guard 12
B Guard 22
B Forward 30
B Forward 9
B Forward 12
B Forward 25
;
run;

/*view dataset*/
proc printdata=my_data;

We can use the following PROC FREQ statement with a WHERE statement to calculate the frequency of values in the position column only for the rows where the team is equal to ‘A’:

/*calculate frequency of position where team is equal to 'A'*/
proc freqdata=my_data;
    where team='A';
    tables position;
run;

The output displays the frequency of the values for the position variable only for the rows where the team is equal to ‘A.’

For example, we can see:

  • The value “Forward” occurs 2 times for team A.
  • The value “Guard” occurs 3 times for team A.

We can also use the OR and AND operators to specify multiple conditions within the WHERE statement.

For example, we can use the following code to calculate the frequency of values in the position column where the team is equal to ‘A’ and the position is equal to ‘Guard’:

/*calculate frequency of position where team is 'A' and position is 'Guard'*/
proc freqdata=my_data;
    where team='A' and position='Guard';
    tables position;
run;

The output displays the frequency of the values for the position variable only for the rows where the team is equal to ‘A’ and the position is equal to ‘Guard.’

Note: You can find the complete documentation for PROC FREQ .

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

Cite this article

stats writer (2024). How can I use PROC FREQ with a WHERE statement to apply the SAS principle of “SAS: Use PROC FREQ with WHERE Statement”?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-use-proc-freq-with-a-where-statement-to-apply-the-sas-principle-of-sas-use-proc-freq-with-where-statement/

stats writer. "How can I use PROC FREQ with a WHERE statement to apply the SAS principle of “SAS: Use PROC FREQ with WHERE Statement”?." PSYCHOLOGICAL SCALES, 25 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-use-proc-freq-with-a-where-statement-to-apply-the-sas-principle-of-sas-use-proc-freq-with-where-statement/.

stats writer. "How can I use PROC FREQ with a WHERE statement to apply the SAS principle of “SAS: Use PROC FREQ with WHERE Statement”?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-use-proc-freq-with-a-where-statement-to-apply-the-sas-principle-of-sas-use-proc-freq-with-where-statement/.

stats writer (2024) 'How can I use PROC FREQ with a WHERE statement to apply the SAS principle of “SAS: Use PROC FREQ with WHERE Statement”?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-use-proc-freq-with-a-where-statement-to-apply-the-sas-principle-of-sas-use-proc-freq-with-where-statement/.

[1] stats writer, "How can I use PROC FREQ with a WHERE statement to apply the SAS principle of “SAS: Use PROC FREQ with WHERE Statement”?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How can I use PROC FREQ with a WHERE statement to apply the SAS principle of “SAS: Use PROC FREQ with WHERE Statement”?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

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