SAS Analyzing and Reporting Data

Tasks Performed by CAS Actions

Analyzing and reporting on your data involves creating summaries or reports based on the data that you prepared in Preparing Data . The following table demonstrates a few basic analytic and reporting tasks.



Action or Procedure


Summarize multiple numeric variables.

mdSummary action

Summarizing Multiple Numeric Variables

Create a Group-by table.

groupBy action

Creating a Group-By Table

Create a gradient map.

SGMAP procedure

Creating a Gradient Map of the United States

Create a frequency table.

freqTab action

Creating a Frequency Table

Summarizing Multiple Numeric Variables

This example summarizes each age group’s eligibility criteria (Income, Payment_History, Credit_Score) and determines the minimum, maximum, and mean values for each criterion. This type of summarization can help monitor each age group’s credit score for future credit qualification.

proc cas; /*1*/ session casauto; simple.mdSummary result=creditsummary status=s / /*2*/ inputs={"Income", "Credit_Score", "Payment_History"} sets={{groupBy={"Age_Range"}}} table={name="creditqualify"} subSet={"MAX", "MIN", "MEAN"} ; run; print creditsummary; /*3*/ run; quit;

  1. The PROC CAS statement enables you to program and schedule SAS Cloud Analytic Services actions from the SAS client.
  2. The mdSummary action calculates summaries of the numeric variables Income, Payment_History, and Credit_Score. The action also groups the MIN, MAX, and MEAN results for the variables in the CreditSummary table for each age range.
  3. The PRINT statement displays the values of the result table, CreditSummary, to the current output location.

simple.mdSummary Action Results (Partial Output)

Creating a Group-By Table

This example groups the CreditQualify table by the State_Name and State variables and uses Credit_Score as the weighting variable. The example then saves the Group-by table to ScorePerState.sashdat in the active caslib for later use.

proc cas; /*1*/ session casauto; simple.groupBy result=r status=s / /*2*/ inputs={"State_name", "State"}, /*3*/ weight="Credit_Score", /*4*/ aggregator="MEAN", /*5*/ scoregt=0, /*6*/ scorelt=900, table={name="creditqualify"}, /*7*/ casout={name="ScorePerState", /*8*/ replace=true}; run; if (s.severity = 0) then do; /*9*/ table.alterTable / columns={ {label="Credit Score", format="5.2" name="_Score_"}}, name="ScorePerState"; table.fetch / format=True, fetchVars={"State_name", "State", {name="_Score_",format="5.2"}}, table={name="ScorePerState"} index=false; / /*10*/ table={name="ScorePerState"}, name="ScorePerState.sashdat", replace=True; end; run; quit;

  1. The PROC CAS statement enables you to program and schedule SAS Cloud Analytic Services actions from the SAS client.
  2. The groupBy action builds BY groups for the CreditQualify table.
  3. The INPUTS= parameter specifies State_Name and State as the input variables. These variables are used to group the table.
  4. The WEIGHT= parameter specifies Credit_Score as the weighting variable.
  5. The AGGREGATOR= parameter specifies MEAN as the aggregator.
  6. The SCOREGT= and SCORELT= options specify the upper and lower bounds of the numeric rank order scores of the distinct groupings to return.
  7. The TABLE= parameter specifies CreditQualify as the input table.
  8. The CASOUT= parameter specifies ScorePerState as the output table in the active caslib. The REPLACE parameter replaces the output table if it already exists.
  9. The IF-THEN/DO statement uses the alterTable action to alter the Credit_Score column. The IF-THEN/DO statement then uses the fetch action to fetch the variables State_Name, State, and _SCORE_ from the ScorePerState table. The action also applies the SAS format 5.2 to the _SCORE_ variable, and then prints the result table.
  10. The save action saves the ScorePerState to a file as ScorePerState.sashdat in the active caslib for later use.

table.fetch Action Results

Creating a Gradient Map of the United States

Converting X and Y Variables from Radians to Degrees

The CHOROMAP statement plots the X (longitude) and Y (latitude) variables from the MAPS data set that contains unprojected latitude and longitude values. To match the projection types, convert the X and Y variables from radians to degrees.

data states; set maps.states; if state ^in(2,15,72); x = -x * 45/atan(1); y = y * 45/atan(1); run;

Creating Plot Data

Create the plot data, which is used by the SGMAP procedure statement and the TEXT statement. Keep only the lower 48 U.S. states, and collect the state Federal Information Processing Standards (FIPS) codes.

data plot_data; set maps.uscenter; if state ^in(2,15,72) and ocean^='Y'; long = -long; statename = fipstate(state); run;

Assigning a Title and Footnote

Use the global TITLE and FOOTNOTE statements.

title 'Average Credit Score in Each State';
footnote4 'Map only includes the lower 48 states in the United States';

Creating the Graph

Run the SGMAP procedure by using as input the states map data set, the U.S. Census Bureau 2010 population response data set, and the plot data set. Use the ESRIMAP statement to create the base map. Use the CHOROMAP statement to plot state populations. Assign state names by using the TEXT statement. Use the GRADLEGEND statement and its options to assign a gradient legend for the states.

proc sgmap mapdata=work.states maprespdata=mycaslib.scoreperstate plotdata=work.plot_data; esrimap url=' Canvas/World_Light_Gray_Base'; choromap _Score_ / mapid=state density=1 numlevels=4 leveltype=none colormodel=( sty greenyellow deepskyblue cornflowerblue beige) name='choro'; text x=long y=lat text=statename / textattrs=(size=6pt); gradlegend 'choro' / title='Average Credit Score' extractscale; run; quit;

SGMAP Procedure Result

Creating a Frequency Table

Counting the Number of People Qualified

This example uses the IF-THEN statement to conditionally apply a count to the number of people who qualified for credit.

data mycaslib.qualifyapps; set mycaslib.creditqualify; if Credit_Qualification='N/A' then Count=0; else Count=1; run;

Creating a Frequency Table

This example uses the freqTab action to determine the percentage of people who qualified for credit.

proc cas; action freqTab.freqTab/ table='qualifyapps', weight='Count', tabulate={'Credit_Qualification'}; quit;

Results from freqTab Action