The example CreditQualify table is created using a DATA step with datalines to ensure the example's autonomy. The data is fictitious and includes the variables State (character string), State_FIPS (numeric), and Credit_Score (numeric).
1 Code Block
PROC CAS / DATA STEP Data
Explanation : The initial DATA step creates a temporary table named 'CreditQualify' with example data for the 'State' (state), 'State_FIPS' (state FIPS code), and 'Credit_Score' (credit score) variables. The PROC CAS statement activates the SAS Cloud Analytic Services (CAS) session. The simple.groupBy action is then used to build groups based on the 'State' and 'State_FIPS' variables. 'Credit_Score' is defined as the weighting variable, and the aggregator is set to 'MEAN' to calculate the average credit scores per group. The 'scoregt' and 'scorelt' options define the lower and upper limits of scores to include. The result of this action is an output table named 'ScorePerState' in the active caslib. A severity code check (s.severity = 0) ensures that subsequent actions are executed only upon success. If the groupBy action succeeds, the table.alterTable action is used to modify the '_Score_' column by assigning it the label 'Credit Score' and format '5.2'. Then, the table.fetch action retrieves the 'State', 'State_FIPS', and '_Score_' variables from the 'ScorePerState' table, applying the specified format for '_Score_'. Finally, the table.save action saves the 'ScorePerState' table in .sashdat format in the active caslib.
Copied!
data work.CreditQualify;
input State $ State_FIPS Credit_Score;
datalines;
NC 37 700
NC 37 750
NY 36 600
NY 36 620
CA 06 800
CA 06 820
;
run;
proc cas;
session mysession;
simple.groupBy result=r status=s /
inputs={"State", "State_FIPS"},
weight="Credit_Score",
aggregator="MEAN",
scoregt=0,
scorelt=900,
table={name="CreditQualify"},
casout={name="ScorePerState",
replace=true};
run;
if (s.severity = 0) then do;
table.alterTable / columns={
{label="Credit Score", format="5.2", name="_Score_"}},
name="ScorePerState";
table.fetch /
format=True,
fetchVars={"State", "State_FIPS",
{name="_Score_",format="5.2"}},
table={name="ScorePerState"},
index=false;
table.save /
table={name="ScorePerState"},
name="ScorePerState.sashdat",
replace=True;
end;
run;
quit;
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.