The examples use generated data (datalines) for the 'creditqualify' table.
1 Code Block
DATA STEP / PROC CAS / simple.groupBy Data
Explanation : This code begins by creating a temporary SAS table named 'creditqualify' via a DATA STEP, populated with fictitious data for the variables 'State', 'State_FIPS', and 'Credit_Score'.
Next, the 'PROC CAS' procedure is used to interact with the Cloud Analytic Services (CAS) service. A CAS session is established ('session mysession').
The 'simple.groupBy' action is called to build groups based on the 'State' and 'State_FIPS' variables from the 'creditqualify' table. 'Credit_Score' is defined as the weighting variable, and 'MEAN' is specified as the aggregator to calculate the average. The 'scoregt' and 'scorelt' options filter the numeric scores from the groupings. The resulting output table is named 'ScorePerState' and is created in the active caslib, replacing any existing table with the same name.
After the 'simple.groupBy' action is executed, a check is performed on the returned severity code (s.severity). If this code is 0, indicating successful execution, an IF-THEN/DO block is executed.
Inside this block, the 'table.alterTable' action is used to modify the 'ScorePerState' table, setting a label ('Credit Score') and a format ('5.2') for the '_Score_' column.
Then, the 'table.fetch' action is called to retrieve and display the 'State', 'State_FIPS' variables, and the '_Score_' column (now formatted) from the 'ScorePerState' table.
Finally, the 'table.save' action is used to persistently save the 'ScorePerState' table as a 'ScorePerState.sashdat' file in the active caslib, ensuring its availability for future use.
Copied!
data creditqualify;
length State $2. State_FIPS $2. Credit_Score 8;
infile datalines;
input State State_FIPS Credit_Score;
datalines;
NC NC 750
NC NC 700
CA CA 800
CA CA 650
TX TX 600
TX TX 720
NY NY 780
NY NY 690
;
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.