The script begins by assigning an external library 'ch4' to a specified data path. It then proceeds with several analyses: 1) counting participants by registration type (RegType), 2) creating and applying a custom format for the 'VegMeal' variable to display 'Yes'/'No' in a detailed report, 3) calculating total fees by regional code (AreaCode) and registration type with monetary formatting, 4) a cross-frequency analysis for the total number and percentage of participants by 'AreaCode' and 'RegType' via PROC FREQ, and 5) a repetition of the previous analysis using PROC TABULATE for the same statistics.
Data Analysis
Type : EXTERNE
Data is read from the 'conference' table in the 'ch4' library. This library is defined by a LIBNAME statement pointing to a specified external local file directory: 'U:\Little-SAS-Book-Exercises-And-Projects\data\EPLSB5data\Chapter4_data'.
1 Code Block
LIBNAME
Explanation : This statement defines the SAS library 'ch4' and associates it with the specified file path. This allows the script to access SAS datasets (.sas7bdat) stored in this directory, notably 'ch4.conference'.
Explanation : This procedure generates a summary table (Part A) that counts the total number of participants for each unique value of the 'RegType' variable (Registration Type) present in the 'ch4.conference' dataset.
Copied!
PROC TABULATE data = ch4.conference;
CLASS RegType;
TABLES RegType;
RUN;
1
PROC TABULATEDATA = ch4.conference;
2
CLASS RegType;
3
TABLES RegType;
4
RUN;
3 Code Block
PROC FORMAT
Explanation : This block creates a custom format named 'needsveg'. It is designed to map numeric values 0 and 1 of the 'VegMeal' variable to the character strings 'No' and 'Yes' respectively, thereby improving readability in reports.
Explanation : Displays a list of conference participants (First Name, Last Name) as well as their vegetarian meal requirement ('VegMeal'). The 'needsveg' format is applied to 'VegMeal' to display 'Yes' or 'No'. A descriptive title is added to the report.
Copied!
PROC PRINT data = ch4.conference;
VAR FirstName LastName VegMeal;
FORMAT VegMeal needsveg.;
TITLE "Meal Requirements for Conference Participants";
RUN;
1
PROC PRINTDATA = ch4.conference;
2
VAR FirstName LastName VegMeal;
3
FORMAT VegMeal needsveg.;
4
TITLE "Meal Requirements for Conference Participants";
5
RUN;
5 Code Block
PROC TABULATE
Explanation : This procedure generates a cross-table (Part C) presenting the sum of fees ('Rate') by regional code ('AreaCode') and registration type ('RegType'). The output is formatted in dollars with two decimal places for better financial presentation.
Copied!
PROC TABULATE data = ch4.conference FORMAT = DOLLAR9.2;
CLASS AreaCode RegType;
VAR Rate;
TABLE AreaCode, SUM=''*Rate=''*RegType="Registration Type";
TITLE "Total Fees Collected Per Area Code and Registration Type";
RUN;
1
PROC TABULATEDATA = ch4.conference FORMAT = DOLLAR9.2;
TITLE "Total Fees Collected Per Area Code and Registration Type";
6
RUN;
6 Code Block
PROC FREQ
Explanation : Creates a cross-frequency table (Part D) for 'AreaCode' and 'RegType'. The LIST option displays each category combination on a separate line, and NOCUM suppresses cumulative percentages, focusing on individual totals and percentages.
Copied!
PROC FREQ data = ch4.conference;
TABLES AreaCode * RegType /
LIST NOCUM;
TITLE "Total and Percent Attendees by Area Code and Registration Type with PROC FREQ";
RUN;
1
PROC FREQDATA = ch4.conference;
2
TABLES AreaCode * RegType /
3
LIST NOCUM;
4
TITLE "Total and Percent Attendees by Area Code and Registration Type with PROC FREQ";
5
RUN;
7 Code Block
PROC TABULATE
Explanation : This block uses PROC TABULATE (Part E) to reproduce the analysis from Part D. It calculates the total number of participants (N) and their overall percentage (PCTN) by 'AreaCode' and 'RegType', offering an alternative and flexible method for presenting statistics.
Copied!
PROC TABULATE data = ch4.conference;
CLASS AreaCode RegType;
TABLE AreaCode, N='Total Count'*RegType='Registration Type' PCTN='Overall Percentage'*RegType='Registration Type';
TITLE "Total and Percent Attendees by Area Code and Registration Type with PROC TABULATE";
RUN;
TITLE "Total and Percent Attendees by Area Code and Registration Type with PROC TABULATE";
5
RUN;
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.