This SAS code processes survey data and generates a multi-sheet...
August 27, 2025 at 08:33 PM
This SAS code processes survey data and generates a multi-sheet Excel report, highlighting specific data conditions. Here's a breakdown of what the code does:
Summary Tab Processing
-
ODS Graphics and Titles Setup:
- Turns on ODS (Output Delivery System) graphics and disables the default procedure title (
ods graphics on
andods noproctitle
).
- Turns on ODS (Output Delivery System) graphics and disables the default procedure title (
-
Frequency Analysis:
- Uses the
proc freq
procedure to compute frequencies of theReport
variable in thesurveys
dataset. The output is written to a new temporary dataset calledSummary
, without displaying the results.
- Uses the
-
Data Manipulation:
- Modifies the
Summary
dataset by:- Rounding the
percent
variable to three decimal places and storing it inPercent_Freq
. - Dropping the original
percent
variable.
- Rounding the
- Modifies the
Export to Excel
-
Initialize Excel Export:
- Defines an Excel file name, including a date from the system macro variable (
&SYSDate
), and specifies the sheet styles and names.
- Defines an Excel file name, including a date from the system macro variable (
-
Sheet: Summary:
- Writes the
Summary
dataset to the first Excel sheet named "Summary" using theproc print
procedure.
- Writes the
-
Sheet: Issues:
- Processes the
Issues
dataset usingproc report
and applies conditional formatting:- Highlights rows by setting the background color of certain variables (
Var23
toVar58
) to red based on specific conditions. For example:- Variables like
Var23
toVar38
are highlighted red if their value is"No"
. - Variables like
Var39
toVar45
are highlighted red if their value is"Dissatisfied"
or"Very Dissatisfied"
. - Variables like
Var55
toVar58
are highlighted red based on specific string matches (e.g.,"IIS resources"
,"Scheduling resources"
).
- Variables like
- Highlights rows by setting the background color of certain variables (
- Processes the
-
Sheet: Comments:
- Writes the contents of the
Comments
dataset to a sheet named "Comments" usingproc print
. The options suppress observation numbers and include labels.
- Writes the contents of the
-
Sheet: RawData:
- Writes the entire
surveys
dataset to a sheet named "RawData" usingproc print
. Observation numbers are suppressed, and labels are included.
- Writes the entire
-
Close Excel Destination:
- Closes the Excel ODS output to ensure all data is written properly.
Final Report
The generated Excel file contains multiple sheets:
- Summary – Summary table of frequencies for the
Report
variable with percentages rounded to 3 decimal places. - Issues – A detailed report from the
Issues
dataset with rows/columns conditionally highlighted in red based on specific values. - Comments – Contents of the
Comments
dataset. - RawData – Entire contents of the
surveys
dataset.
The conditional formatting helps highlight problem areas (specific responses) in the "Issues" sheet.
Generate your own explanations
Download our vscode extension
Read other generated explanations
Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node