# PROC FREQUENCY on SAS - 9TO5SAS (2023)

PROZ FREQUENCYin SAS is a method to analyze the number of data. It is used to obtain frequency counts for one or more individual variables or to create double-entry tables (crosstabs) of two variables.

Omron CP1H table data instructions

Omron CP1H table data instructions

PROC FREQ in SAS can also perform statistical tests on count data.

PROCESSING MEANSis another SAS technique that allows you to calculate descriptive statistics such as mean, standard deviation, minimum and maximum values, and many other statistical calculations.

Syntax:

`PROC FREQ <option(s)>; <statements> TABLES requirements </options> ;`

content of page

## Testify

### TABLE declaration

The table declaration in PROC FREQ returns the frequency or count of the specified columns.

You can specify options for the TABLE statement followed by a forward slash (/).

Examples:

The basic use of PROC FREQ in SAS is to obtain counts of the number of observed students in each gender category. We can use the following code:

``process frequency data = sashelp.class; table sex; run;``

`TABLES Age*Weight/CHISQ;`

(Video) Updated: SAS Proc SQL eliminate dups Using the DISTINCT Keyword

The above explanation requires that Chi-Square and related statistics be reported for Crosstab A*B.

## UNIDIRECTIONAL frequency tables

You can use PROC FREQ in SAS to create frequency tables/counts by category and work with the counts.

### Using the ORDER=FREQ option

``proc freq data=data.flighttravelers order=frequency; table day_of_the_reservation; execute;``
• PROC FREQ includes the ORDER=FREQ option in the example above.
• The ORDER=FREQ option helps you quickly analyze which categories have the most and least counts.
• The "Frequency" column indicates how often the day_of_booking variable takes the value of the column.
• The Percentage column is the percentage of the grand total.
• The Cumulative Frequency and Percentage columns indicate an increase in count and percentage for the day_of_booking values.

For example, in this data, 28 people booked flights on Sunday.

### Using the option REQUEST=FORMAT.

You can use the ORDER=FORMAT option to control the order in which the categories are displayed in the table.

Before using this option, you must createa custom format to define the orderyou want at the output.

``process format; value \$dayfmt "Saturday"="Weekends" OTHER="Weekdays";run;proc freq order=formatted data=data.flighttravelers; day_of_reservation tables; Title "Example of PROC FREQ with formatted values"; day_of_booking format \$dayfmt.;run;``

## Create a ONE-WAY frequency table from summary data

If the data is already summarized, you can use thatWEIGHTstatement to specify the variables that represent the count.

``DATA COINS; TICKET CATEGORY \$9. COUNT 3rd; DATALINES;CENT 152CENT 100NICKELS 49DIMES 59QUARTERS 21HALF 44DOLLARS 21;PROC FREQ; WEIGHT NUMBER; TITLE 'Read summary count data'; TABLES CATEGORY; EXECUTE;``

WEIGHTCOUNT tells PROC FREQ that the data for the COUNT variable is a count. Although there are two records for CENTS, the program can combine the WEIGHT into a single category of CENTS (252 CENTS).

## Testing goodness-of-fit on a one-way table

A single population goodness-of-fit test is a test used to determine whether the distribution of observed counts in the sample data represents the expected number of occurrences for the population.

Assuming that the number of observations is fixed.

The hypotheses tested are the following:

H:0The population follows the hypothesized distribution.H:AThe population does not follow the hypothesized distribution.

A chi-square test is one of the goodness tests. Based on that, a decision can be made. -Value associated with this statistic.

a bass -value indicates that the data does not follow the hypothesized or theoretical distribution.

If he is low enough (typically <0.05), it will reject the null hypothesis.

The syntax for performing a fit test is as follows:

`PROC FREQUENCY; TABLES variable / CHIQ TESTP=(list of reasons);`

Example:

An airline operated daily flights to various Indian cities. One of the airline's problems is the food preferences of passengers. The captain, the head chef, believes that 35% of his passengers prefer vegetarian food and 40% prefer vegetarian food. 20% hypocaloric diet and 5% need for diabetic diet.

(Video) Introduction to Proc Reg in SAS

A sample of 500 passengers was randomly selected to analyze food preferences and the data is shown below.

We will perform a CHI-SQUARE test to verify that Captain Cook's belief is true. =0,05

Solution:

``proc freq data=airlines order=data; weight no_of_passengers; Title "Analysis of Adaptation"; Tables of types of food / nocum chisq testp=(0.35 0.40 0.20 0.05);run;``
• HeWEIGHTNumber_of_passengers summarizes the data.
• HeORDER=DATAis used to order the data as in the input data set. The counts are based on the Food_Type variable.
• He/ NIGHT CHRISTMASYPROOF= The statements are used to compute the goodness test.
• Test rates are based on the percentage of offspring expected from each of the four categories.
• HeNOKUMThe option requests a table without the cumulative column.

Note: you must use theORDER=DATAOption to ensure that hypothetical indices are listed in thePROOF= statements correctly match categories in input data.

The p-value for the chi-square test ( =7.4107) is greater than the critical value ( =0.05), so we conclude that Captain Cook's belief about food preferences is true.

## CHI SQUARE Test of Independence - Two-Way Table Analysis

We test whether two or more groups are statistically independent in the chi-square test of independence.

The TABLES statement with two or more variables enumerated and separated by an asterisk creates a crosstab to relate two variables.

Crosstabulation is often referred to ascontingency table.

The number of occurrences in a sample across two grouping variables creates a crosstab.

In the following example we want to determine the connection between crime and alcohol consumption.

The independent variable is CRIME and the dependent variable is DRINKER.

So the crosstab statement will be

`CRIME*DRINK TABLES`

The null and alternative hypothesis in this case is: : The variables are independent, that is, there is no association between crime and alcohol consumption : The variables are dependent, which means that the crime rate depends on alcohol consumption

``process frequency data = drinker; weight count; Table Crime*Trinker/Chisq wait norow nocol nopercent; title 'Chi-square analysis of a contingency table';run;``

By default, the table displays a total of four numbers in each cell.Frequency,Diefull percentage, Diepercent line, and thepercentage columnAs follows.

HeEXPECTEDindicates that the expected values ​​should be included in the table, andNOROW,NOCOL, YNINE PERCENTinstruct SAS to exclude these values ​​from the table.

Look at the output statistics. The chi-square value is 49.5660 and .

This rejects the null hypothesis, i. h there is no association (independence), and they conclude that there is evidence of an association between alcohol consumption and the type of crime committed.

Most of the expected values ​​are close to the observed values, while in the case of cheating the observed value (63) differs from the expected (109,14).

This information suggests that scammers are less likely to drink alcohol.

## Calculation of relative risk

Two-by-two crosstabulations are often used when examining a measure of risk. In a medical exam, these tables are created when one variable represents the presence or absence of a disease and the other indicates a risk factor.

A measure of this risk in a case-control study is calledOdds Ratio (OR).

In a case-control study, a researcher takes a sample of subjects and looks back in time to determine whether or not they were exposed to a disease.

In a cohort study, subjects are selected for the presence or absence of risk and then followed over time to see if they develop an outcome; is the measure of this riskrelatives Risiko (RR).

The ODDS ratio indicates how much more likely it is to find exposure in someone with the disease compared to exposure in someone without the disease.

The relative risk indicates how often an exposed person is more or less likely to develop an outcome compared to an unexposed person.

In both cases, a measure of risk (OR or RR) equal to 1 indicates no risk.

A risk measure other than 1 represents a risk The belief that the outcome being studied is undesirable.

• Risk measure >1 indicates a higher risk of the outcome.
• Risk measure <1 implies a reduced risk of the outcome.
• Risk measure = 1 indicates no risk.

In PROC FREQ, the option to compute the values ​​for OR or RR is RELRISK, and it appears as an option to the TABLES statement, as shown here:

`TABLAS CHOLESTROLDIET*RESULT / CHISQ RELRISK;`

Example

``proc freq data=HeartDisese order=data; Title “High Fat/Cholesterol Diet Case-Control Study”; TABLES CHOLESTROLDIET*RESULT / CHISQ RELRISK; exact pchi or; total weight; barrel;``

The frequency tells us how many subjects have heart disease on the LOW cholesterol diet with a NO/YES result.

If we interpret the first row, we have 6 subjects with LOW cholesterol who do NOT have heart disease, while 2 subjects with LOW cholesterol have HEART disease.

Expected gives the actual value to the observed value.

The percentage is the overall percentage indicating that 26.09% of people follow a low cholesterol diet and do not have heart disease.

ROW Percent gives us the percentage of subjects on the low cholesterol diet who did NOT have heart disease out of 8 subjects on the low cholesterol diet. that is, 75% of people with LOW cholesterol do not have heart disease.

CHOL Percentage gives us the percentage of subjects who did not have CHD on a low cholesterol diet. that is to say 6 out of 10, that is to say 60%. At the same time, 80% of people with heart disease eat a high cholesterol diet.

The interpretation of the CHI-SQUARE test tells us the association of these variables between what is expected and what is observed.

The chi-square statistic (4.9597) is smaller than the p-value (0.0259), indicating an association between what is expected and what is observed.

The warning

One of the assumptions of the CHI-SQUARE test is that the observed value must be greater than 5 in each cell. In the example above, we have 4 and 2, which is less than 5. In these cases, it is more appropriate to use Fisher's exact test.

Fisher's exact test (0.0393) which is statistically significant at 5% . So we can say that there is a link, and perhaps a high fat diet is associated with a HIGH risk of heart disease.

HeEXACTLYstatement is forPICHI, which means the P-value for the CHI-SQUARE outputs in the table below.  probability– 8.25 with a 95% confidence limit, which means that people are 8 times more likely to have heart disease than people without heart disease

HeRisiko relativesof 2.88 indicates that heart disease is 2.88 times more common in the high-fat group. (Higher risk).

The relative risk of 0.34 tells us that there is a reduced risk (0.34 times lower) of LOW cholesterol and heart disease.

Since we specify EXACT in the ODD relation, we get the last table as shown below.

The odds ratio is the same as above, which is 8.25, but it also gives the exact confidence limit.

## FAQs

### How do you write PROC FREQ in SAS? ›

Syntax. PROC FREQ DATA=sample ORDER=freq; TABLE State Rank; RUN; The ORDER=freq option in the first line of the syntax tells SAS to order the values in the table in descending order.

What does proc FREQ count in SAS? ›

The PROC FREQ is one of the most frequently used SAS procedures which helps to summarize categorical variable. It calculates count/frequency and cumulative frequency of categories of a categorical variable.

How do you find the output of PROC FREQ? ›

PROC FREQ produces two types of output data sets that you can use with other statistical and reporting procedures. You can request these data sets as follows: Specify the OUT= option in a TABLES statement. This creates an output data set that contains frequency or crosstabulation table counts and percentages.

What is frequency missing in Proc FREQ? ›

PROC FREQ treats missing BY variable values like any other BY variable value. The missing values form a separate BY group. If an observation has a missing value for a variable in a TABLES request, by default PROC FREQ does not include that observation in the frequency or crosstabulation table.

What is proc format in proc freq? ›

PROC FREQ uses the entire value of a character format to classify an observation. You can also use the FORMAT statement to assign formats that were created with the FORMAT procedure to the variables. User-written formats determine the number of levels for a variable and provide labels for a table.

How do you keep variables in Proc Freq? ›

If you have multiple variables you would need one table statement per variable. Use other options that will create data sets that have different structures: proc freq data=sashelp. class; ods output onewayfreqs= work.

Why do we use proc frequency? ›

Proc FREQ is a procedure that is used to give descriptive statistics about a particular data set. Proc FREQ is used to create frequency and cross-tabulation tables. It enables analysis at various levels. Associations between variables and responses can be tested and computed.

What is Proc freq with total count? ›

PROC FREQ in SAS is a procedure for analyzing the count of data. It is used to obtain frequency counts for one or more individual variables or to create two-way tables (cross-tabulations) from two variables. PROC FREQ in SAS can also perform statistical tests on count data.

How do you count frequency by group in SAS? ›

You can use the following basic syntax to calculate frequencies by group in SAS: proc freq data=my_data; by var1; tables var2; run; This particular syntax creates a frequency table for the values of the variable called var2, grouped by the variable called var1.

What is the difference between table and tables in SAS PROC freq? ›

There is no difference. The statement is the TABLES statement, but SAS will silently accept TABLE as a synonym without issuing any warning or note. Some miss spellings will generate just a warning while others will cause an error. 1668 proc freq data= sashelp.

### What is the difference between proc freq and proc means? ›

Difference between PROC MEANS and PROC FREQ

PROC MEANS is used to calculate summary statistics such as mean, count etc of numeric variables. It requires at least one numeric variable whereas Proc Freq does not have such limitation.

What does the output of Proc freq not contain? ›

By default, PROC FREQ does not include missing combinations in the LIST display or the OUT= output data set. To include missing combinations in the LIST display and the OUT= output data set, you can specify the SPARSE option in the TABLES statement.

Does Proc freq show missing values? ›

PROC FREQ also reports the number of missing values in output data sets. The TABLES statement OUT= data set includes an observation that contains the missing value frequency. The NMISS option in the OUTPUT statement provides an output data set variable that contains the missing value frequency.

How do you show frequency? ›

A frequency distribution of data can be shown in a table or graph. Some common methods of showing frequency distributions include frequency tables, histograms or bar charts.

Can you group in Proc FREQ? ›

PROC FREQ groups a variable's values according to its formatted values. If you assign a format to a variable with a FORMAT statement, PROC FREQ formats the variable values before dividing observations into the levels of a frequency or crosstabulation table.

Which statements are true concerning the FREQ procedure? ›

Which statements are true concerning the FREQ procedure? b. The ORDER=FREQ option can be placed in the PROC FREQ statement to display the column values in descending frequency count order.

What is best format in SAS? ›

When a format is not specified for writing a numeric value, SAS uses the BEST w. format as the default format. The BEST w. format attempts to write numbers that balance the conflicting requirements of readability, precision, and brevity.

How can you get the frequency of different levels in a categorical column? ›

To create a frequency column for categorical variable in an R data frame, we can use the transform function by defining the length of categorical variable using ave function. The output will have the duplicated frequencies as one value in the categorical column is likely to be repeated.

Is frequency the same as count? ›

In statistics, however, the term refers to a count of items in a data set. This meaning of “frequency” as synonymous with “count” has been adopted by one major text and the Behavior Analyst Certification Board®. Another major text uses “frequency” and “rate” interchangeably when referring to behaviors per unit time.

What is an example of a frequency count? ›

A frequency is the number of times a data value occurs. For example, if four people have an IQ of between 118 and 125, then an IQ of 118 to 125 has a frequency of 4.

### What is total frequency of the given data? ›

The frequency of a particular data is the number of times the data value occurs. We represent the frequency of a data value by f. For example, if five students got an A in science, and then the grade A is said to have a frequency of 5.

What is frequency count method? ›

The tally or frequency count is the calculation of how many people fit into a certain category or the number of times a characteristic occurs. This calculation is expressed by both the absolute (actual number) and relative (percentage) totals.

How is frequency band calculated? ›

The bandwidth frequency is that at which the response of the device is reduced by 3 dB (or 30%), that is, the output signal V0 is 0.707 of the mid-frequency value [and the output power is half of the mid-frequency value, from the following expression: response or gain (in dB)=10log10(V02/Vref2)].

How do you find the frequency of each element in an array? ›

Algorithm
1. Declare and initialize an array arr.
2. Declare another array fr with the same size of array arr. ...
3. Variable visited will be initialized with the value -1. ...
4. The frequency of an element can be counted using two loops. ...
5. Initialize count to 1 in the first loop to maintain a count of each element.

Is a two way table the same as a frequency table? ›

Two way tables are also called frequency tables and contingency tables.

Which is not a part of proc freq? ›

Q2) Which one of the following statement can't be part of “PROC FREQ”? Look at the syntax of PROC FREQ, there is not SET statement required.

Is a frequency table the same as a contingency table? ›

Frequency tables show counts or proportions within groups of categorical variables. Contingency tables analyse the relationship between several categorical variables by (1) placing some variables into rows and other variables into columns and (2) calculating some meaningful statistics: counts, sum, average etc.

What does proc rate mean? ›

What is the definition of Proc? Proc stands for Programmed Random Occurrence.

What is the weight zero option in proc freq? ›

If the value of the WEIGHT variable is 0, PROC FREQ ignores the observation unless you specify the ZEROS option, which includes observations that have weights of 0. If you do not specify a WEIGHT statement, PROC FREQ assigns a weight of 1 to each observation.

How do you write a proc format? ›

The general form of PROC FORMAT is: PROC FORMAT; VALUE format-name Data-value-1 = 'Label 1' Data-value-2 = 'Label 2'; VALUE format-name-2 Data-value-3 = 'Label 3' Data-value-4 = 'Label 4'; .....; RUN; The first line is the start of the proc step.

### How do I format a function in SAS? ›

Using a Function to Format Values
1. Use the FCMP procedure to create the function.
2. Use the OPTIONS statement to make the function available to SAS by specifying the location of the function in the CMPLIB= system option.
3. Use the FORMAT procedure to create a new format.
4. Use the new format in your SAS program.

What is value range in proc format? ›

Each value-or-range can be up to 32,767 characters. If value-or-range has more than 32,767 characters, then the procedure truncates the value after it processes the first 32,767 characters. Note: You do not have to account for every value on the left side of the equal sign.

What is proc format value in SAS? ›

PROC FORMAT is a procedure that creates map- pings of data values into data labels. The user de- fined FORMAT mapping is independent of a SAS DATASET and variables and must be explicitly as- signed in a subsequent DATASTEP and/or PROC. PROC FORMAT will not allow 1-to-many or many- to-many mappings.

Does SAS need coding? ›

Is coding required for SAS? A Statistical Analysis Software aspirant is not required to have any prior knowledge of programming. SAS is easy to learn as it has a simple graphic user interface.

What is a proc step in SAS? ›

A group of SAS procedure statements is called a PROC step. SAS procedures analyze data in SAS data sets to produce statistics, tables, reports, charts, and plots, to create SQL queries, and to perform other analyses and operations on your data. SAS procedures also give you ways to manage and print SAS files.

What language is SAS code? ›

The SAS language is a computer programming language used for statistical analysis, created by Anthony James Barr at North Carolina State University. It can read in data from common spreadsheets and databases and output the results of statistical analyses in tables, graphs, and as RTF, HTML and PDF documents.

How to use %let in SAS? ›

%LET statement is used to create and assign value to macro variables. % LET <Macro Variable Name>=Value; Macro variable name follows the SAS naming convention and if variable already exists then value is overwritten. Macro variables are referenced by using ampersand (&) followed by macro variable name.

How do I extract numbers from text in SAS? ›

The easiest way to extract numbers from a string in SAS is to use the COMPRESS function with the 'A' modifier. This function uses the following basic syntax: data new_data; set original_data; numbers_only = compress(some_string, '', 'A'); run; The following example shows how to use this syntax in practice.

What are the best practices for SAS code comments? ›

Every SAS program should start with a main block of comments, emphasized by asterisks. The block of comments should include the filename, by whom the program is written, the date on which the program was written, and text that clearly describes the main purpose, input and output of the program.

What does F4 do in SAS? ›

Keyboard Shortcuts
ActionKeyboard Shortcut for Microsoft Windows
Open a pop-up menu in the code editor.Shift+F10
Create a new SAS program.F4
Save the SAS program.Ensure that the Code tab for a SAS program is displayed, and press Ctrl+S. Note: This shortcut does not work for the Code tab that displays a task's XML code.
50 more rows

### Can you write functions in SAS? ›

Functions return either numeric or character results. The value that is returned can be used in an assignment statement or elsewhere in expressions. Many functions are included with SAS, and you can write your own functions as well. You can use FCMP Procedure in Base SAS Procedures Guide to create customized functions.

How do I convert Excel to SAS? ›

Importing Excel Files into SAS 9.3 (32-bit) Using the Import Wizard
1. A new window will pop up, called "Import Wizard – Select import type".
2. This first screen will ask you to choose the type of data you wish to import. ...
3. Once you've added the file path to the text box, click OK.
Jan 27, 2023

Top Articles
Latest Posts
Article information

Author: Carlyn Walter

Last Updated: 18/08/2023

Views: 6071

Rating: 5 / 5 (70 voted)

Author information

Name: Carlyn Walter

Birthday: 1996-01-03

Address: Suite 452 40815 Denyse Extensions, Sengermouth, OR 42374

Phone: +8501809515404

Job: Manufacturing Technician

Hobby: Table tennis, Archery, Vacation, Metal detecting, Yo-yoing, Crocheting, Creative writing

Introduction: My name is Carlyn Walter, I am a lively, glamorous, healthy, clean, powerful, calm, combative person who loves writing and wants to share my knowledge and understanding with you.