Data Analysis SAS VIYA CAS

Beyond PROC FREQ: Generating High-Performance Frequency Tables with SAS Viya Actions

This code is also available in: Deutsch Español Français
Difficulty Level
Beginner
Published on :
Simon

Expert Advice

Simon
Expert SAS et fondateur.

Using a computed 0/1 variable as a Weight (as shown in your code with Count) is a powerful alternative to using a WHERE clause. A WHERE clause physically removes observations from the analysis entirely, whereas a weight of 0 simply excludes that specific observation from the frequency count while keeping the row available for other simultaneous calculations or actions that might need it.

Use weighting to filter your analysis without physically removing data.
The example proceeds in two steps. First, a DATA step is used to create a new table `mycaslib.qualifyapps` based on an existing table `mycaslib.creditqualify`. A new variable `Count` is added, taking the value 0 if 'Credit_Qualification' is 'N/A' and 1 otherwise. Second, the `freqTab.freqTab` action of PROC CAS is employed to generate a frequency table for the 'Credit_Qualification' variable, using the 'Count' variable as a weight. This allows determining the percentage of people qualified for credit.
Data Analysis

Type : CREATION_INTERNE


The examples use data (mycaslib.creditqualify) that is assumed to exist in the CAS library 'mycaslib'. The first step creates a new table (mycaslib.qualifyapps) from it, to be used in the second step. To make the example self-contained, the 'mycaslib.creditqualify' table should be created or be a SASHELP dataset.

1 Code Block
DATA STEP Data
Explanation :
This DATA step code creates a new table named `mycaslib.qualifyapps`. It reads data from `mycaslib.creditqualify` and adds a `Count` variable. If 'Credit_Qualification' is 'N/A', `Count` is set to 0; otherwise, `Count` is set to 1.
Copied!
1DATA mycaslib.qualifyapps;
2 SET mycaslib.creditqualify;
3 IF Credit_Qualification='N/A' THEN Count=0;
4 ELSE Count=1;
5RUN;
2 Code Block
PROC CAS
Explanation :
This section uses the `freqTab.freqTab` action of PROC CAS to generate a frequency table. It takes the `qualifyapps` table created previously, uses the `Count` variable as a weight, and calculates frequencies for the `Credit_Qualification` variable. This allows obtaining the distribution of credit qualifications.
Copied!
1PROC CAS;
2 ACTION freqTab.freqTab/
3 TABLE='qualifyapps',
4 weight='Count',
5 tabulate={'Credit_Qualification'};
6QUIT;
Pro Tip
If your goal is simply to exclude rows, using the where= parameter directly inside the CAS action is often more memory-efficient than creating a new physical column like Count.
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright © SAS Institute Inc. All Rights Reserved


Related Documentation

Aucune documentation spécifique pour cette catégorie.