This segment is the last major topic to be tested on the Specialist SAS Base exam and the whole guide is found here: SAS Exam: Complete Guide.

To look at some SAS Base Exam Questions to practice your SAS skills, go to the SAS Base Programming Exam Questions page.

Generate list reports using the PRINT procedure.

Modify the default behavior of PROC PRINT by adding statements and options such as

– Use the VAR statement to select and order variables.– Calculate totals with a SUM statement.– Select observations with a WHERE statement.

``````
data work.class;
set sashelp.class;
retain sumHeight 0;
retain sumWeight 0;

* Calculate totals with a SUM statement;
sumHeight + Height;
sumWeight + Weight;
run;

proc print data=work.class;
*  Use the VAR statement to select and order variables;
var Name Age Sex sumHeight sumWeight;

* Select observations with a WHERE statement;
where sumHeight > 150 and sumWeight > 100;
run;
``````

Output:

– Use the ID statement to identify observations.– Use the BY statement to process groups.

``````
data work.class;
set sashelp.class;
retain sumHeight 0;
retain sumWeight 0;

* Calculate totals with a SUM statement;
sumHeight + Height;
sumWeight + Weight;
run;

proc sort data=work.class;
by Sex;
run;

proc print data=work.class;
*  Use the BY statement to process groups;
id Sex;

*  Use the BY statement to process groups;
by Sex;
run;
``````

Output:

Generate summary reports and frequency tables using base SAS procedures.

Produce one-way and two-way frequency tables with the FREQ procedure.

``````
/* Produce one-way and two-way frequency tables with the FREQ procedure */
proc freq data=sashelp.class;
title 'Frequency of genders in the class';
tables Sex;
run;

proc freq data=sashelp.class;
title 'Frequency of genders and height in the class';
tables Sex Height;
run;
``````

Output:

Enhance frequency tables with options.

For options regarding the SAS Freq table options, please use the following SAS documentation here.

Use PROC FREQ to validate data in a SAS data set

We, can use PROC FREQ to check how frequent the Car Make ‘Lexus’ appears and use PROC PRINT to confirm that there is that many Lexus Car’s and the rest of the details. We will be using the sashelp.cars dataset:

``````
proc freq data=sashelp.cars;
tables make;
run;

proc print data=sashelp.cars;
where make = 'Lexus';
run;
``````

PROC FREQ Output:

PROC PRINT OUTPUT:

Calculate summary statistics and multilevel summaries using the MEANS procedure

``````
/* Calculate summary statistics and multilevel summaries using the MEANS procedure */
title 'Summary statistics using the MEANS procedure';
proc means data=sashelp.cars;
var EngineSize Cylinders Horsepower;
run;

title 'Multilevel summaries using the MEANS procedure';
proc means data=sashelp.cars;
class Make Type;
var EngineSize Cylinders Horsepower;
run;

title '';
``````

Output:

Enhance summary tables with options.

Options for PROC MEANS can be found here.

Identify extreme and missing values with the UNIVARIATE procedure

``````
data BPressure;
length PatientID \$2;
input PatientID \$ Systolic Diastolic @@;
datalines;
CK 120 50  SS 96  60 FR 100 70
CP 120 75  BL 140 90 ES 120 70
CP 165 110 JI 110 40 MC 119 66
FC 125 76  RW 133 60 KD 108 54
DS 110 50  JW 130 80 BH 120 65
JW 134 80  SB 118 76 NS 122 78
GS 122 70  AB 122 78 EC 112 62
HH 122 82
;

/* Identify extreme and missing values with the UNIVARIATE procedure */
title 'Extreme Blood Pressure Observations';
ods select ExtremeObs;
proc univariate data=BPressure;
var Systolic Diastolic;
id PatientID;
run;
``````

Output:

Enhance reports system user-defined formats, titles, footnotes and SAS System reporting options.

Use the LABEL statement to define descriptive column headings.Control the use of column headings with the LABEL and SPLIT=options in Proc Print output.

``````
/* Use the LABEL statement to define descriptive column headings */
title 'Use the LABEL statement to define descriptive column headings';
proc print data=sashelp.cars(obs=3) label ;
label Make = 'Brand';
run;

/* Control the use of column headings with the LABEL and SPLIT=options in Proc Print output */
title 'Control the use of column headings with the LABEL and SPLIT=options in Proc Print output';
proc print data=sashelp.cars(obs=3) label split=' ';
label Origin = 'LocatedAt';
run;
``````

Output:

Generate reports using ODS statements.

Identify the Output Delivery System destinations.

From the SAS Documentation we have the destinations:

Create HTML, PDF, RTF, and files with ODS statements.

``````
/* HTML document created using the ODS statement */
ods html body = '/folders/myfolders/test.htm';

proc print data = sashelp.cars;
run;

ods html close;

/* PDF document created using the ODS statement */
ods pdf file = '/folders/myfolders/test.pdf';

proc print data = sashelp.cars;
run;

ods pdf close;

/* RTF document created using the ODS statement */
ods rtf file = '/folders/myfolders/test.rtf';

proc print data = sashelp.cars;
run;

ods rtf close;
``````

Output:
The files created above will be put in the directory ‘/folders/myfolders/test.fileformat’ as specified in the ODS statement.

Use the STYLE=option to specify a style template.

List of STYLE=option options are listed in the documentation as is used to change the appearance of the output document above. The STYLE=option is used with the opening ODS statement.

Create files that can be viewed in Microsoft Excel.

``````
/* Create files that can be viewed in Microsoft Excel */
ods excel file = '/folders/myfolders/test.xlsx';

proc print data = sashelp.cars;
run;

ods excel close;
``````

Create a simple raw data file by using the EXPORT procedure as an alternative to the DATA step.

``````
/* Create a simple raw data file by using the EXPORT procedure as an alternative to the DATA step */
proc export data=sashelp.cars outfile='/folders/myfolders/test.txt' replace;
run;
``````

Output:
This will take in the sashelp.cars dataset and output it as a text file into the directory ‘/folders/myfolders/’ with the replace option to replace the file in the directory if it currently exists.

Export data to Microsoft Excel using the SAS/ACCESS XLSX engine

``````
/* Export data to Microsoft Excel using the SAS/ACCESS XLSX engine */
libname xl xlsx '/folders/myfolders/test.xlsx';
data xl.cars;
set sashelp.cars;
run;
libname xl clear;
``````

Partial Output (from the Excel file):