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!
data mycaslib.qualifyapps;
set mycaslib.creditqualify;
if Credit_Qualification='N/A' then Count=0;
else Count=1;
run;
1
DATA mycaslib.qualifyapps;
2
SET mycaslib.creditqualify;
3
IF Credit_Qualification='N/A'THEN Count=0;
4
ELSE Count=1;
5
RUN;
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.
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.