%em_register(key=Class, type=data);
data &em_user_Class; set Sashelp.Class;
%em_model( target=BAD, assess=Y, decscorecode=Y, fitstatistics=Y, classification=Y, residuals=Y, predicted=Y);
filename fref "path-name\mycode.sas"; %inc fref; filename fref;
filename fref catalog "libref.mycatalog.myentry.source"; %inc fref; filename fref;
proc means data=&em_import_data; output out=m; run;
logage= log(age);
proc print data=m; run;
/* perform PROC MEANS on interval variables in training data */ /* output the results to data set named t */ proc means data=&em_import_data noprint; var %em_interval; output out=t; run; /* drop unneeded variables and observations */ data t; set t; drop _freq_ _type_; where _stat_ ne 'N'; run; /* transpose the data set */ proc transpose data=t out=tt; id _stat_; run; /* add a variable to identify data partition */ data tt; set tt; length datarole $8; datarole='train'; run; /* perform PROC MEANS on interval variables in validation data */ /* output the results to data set named v */ proc means data=&em_import_validate noprint; var %em_interval; output out=v; run; /* drop unneeded variables and observations */ data v; set v; drop _freq_ _type_; where _stat_ ne 'N'; run; /* transpose the data set */ proc transpose data=v out=tv; id _stat_; run; /* add a variable to identify data partition */ data tv; set tv; length datarole $8; datarole='valid'; run; /* append the validation data results */ /* to the training data results */ proc append base=tt data=tv; run; /* register the key Comp and */ /* create a permanent data set so */ /* that the data set can be used */ /* later in Report code */ %em_register(key=Comp, type=data); data &em_user_Comp; length _name_ $12; label _name_ = 'Name'; set tt; cv=std/mean; run; /* tabulate the results */ proc tabulate data=&em_user_Comp; class _name_ datarole; var min mean max std vc; table _name_*datarole, min mean max std cv; keylabel sum=' '; title 'Distribution Comparison'; run;
%macro intcompare(); %let cv=0; %if "em_import_validate" ne "" and (%sysfunc(exist(&em_import_validate)) or %sysfunc(exist(&em_import_validate, VIEW))) %then %let cv=1; proc means data=&em_import_data noprint; var %em_interval; output out=t; run; data t; set t; drop _freq_ _type_; where _stat_ ne 'N'; run; proc transpose data=t out=tt; id _stat_; run; data tt; set tt; length datarole $8; datarole='train'; run; %if &cv %then %do; proc means data=&em_import_validate noprint; var %em_interval; output out=v; run; data v; set v; drop _freq_ _type_; where _stat_ ne 'N'; run; proc transpose data=v out=tv; id _stat_; run; data tv; set tv; length datarole $8; datarole='valid'; run; proc append base=tt data=tv; run; %em_register(key=Comp, type=data); data &em_user_Comp; length _name_ $12; label _name_ = 'Name'; set tt; cv=std/mean; run; %end; %else %do; %put &em_codebar; %put %str(VALIDATION DATA SET NOT FOUND!); %put &em_codebar; %end; proc tabulate data=&em_user_Comp; class _name_ datarole; var min mean max std cv; table _name_*datarole, min mean max std cv; keylabel sum=' '; title 'Distribution Comparison'; run; %mend intcompare; %intcompare();
/* initialize the &em_user_Comp macro variable */ %em_getname(key=Comp, type=data); /*** Save Results with EM Name ***/ proc sort data=&em_user_Comp out=&em_user_Comp; by descending cv; run; /*** Add to EM Results ***/ %em_report(key=Comp, viewtype=Data, block=Compare, description=Comparison Table); %em_report(key=Comp, viewtype=Bar, x=_name_, freq=cv, block=Compare, where= datarole eq 'train', autodisplay=Y, description=Training Data CV Plot); %em_report(key=Comp, viewtype=Bar, x=_name_, freq=cv, block=Compare, where= datarole eq 'valid', autodisplay=Y, description=Validation Data CV Plot); run;
/* Add Score Code */ %macro scorecode(file); data _null_; length var $32; filename X "&file"; FILE X; set &em_user_Comp(where=(datarole eq 'train')); if _N_ eq 1 then do; put '*----------------------------------------------*;'; put '*---------- Squared Variation Scaling ---------*;'; put '*----------------------------------------------*;'; end; var=strip('V_' !! _name_); put var '= (' _name_ '-' mean ')**2 ;' ; run; %mend scorecode; %scorecode(&em_file_emflowscorecode); %scorecode(&em_file_empublishscorecode);
/* Modify Exported Training Metadata */ data _null_; length string $34; filename X "&em_file_cdelta_train"; FILE X; set &em_user_Comp( where=(datarole eq 'train')); /* Reject Original Variable */ string = upcase('"'!!strip(_NAME_)!!'"'); put 'if upcase(NAME) eq ' string ' then role="REJECTED" ;' ; /* Modify New Variables */ var=upcase(strip('V_' !! _name_ )); string = '"'!!strip(var)!!'"'; put 'if upcase(NAME) eq ' string ' then do ;' ; put ' role="INPUT" ;' ; put ' level= "INTERVAL" ;' ; put ' comment= "Squared Variation" ;' ; put 'end ;' ; run;
/* Register User Files */ %em_register( key=Fit, type=Data); %em_register( key=Est, type=Data); /* Training Regression Model */ /* Create a DMDB database */ %em_dmdb(out=1); /* Fit logistic regression model */ /* using macro %em_dmreg from the */ /* sashelp.emutil catalog */ %em_dmreg( selection=Stepwise, outest=&em_user_Est, outselect=Work.Outselect); /* Work.Outselect contains the names of REJECTED variables */ /* &em_user_Est contains parameter estimates and t statistics */ /* for each of the stepwise models */ /* Modify Exported Metadata */ data _null_; length string $34; filename X "&em_file_cdelta_train"; FILE X; if _N_=1 then do; put "if ROLE in ('INPUT','REJECTED') then do;"; put "if NAME in ("; end; set Work.Outselect end=eof; string = '"'!!trim(left(TERM))!!'"'; put string; if eof then do; put ') then role="INPUT";'; put 'else role="REJECTED";'; put 'end;'; end; run;
/* Generate Graphs */ proc univariate data=&em_import_data noprint; class &em_dec_target; histogram %em_interval_input; run;
C:\EMPROJECTS
.
If your project name is SASCODE and your diagram ID is EMWS1, the
GIF files are stored in C:\EMPROJECTS\SASCODE\WORKSPACES\EMWS1\EMCODE\REPORTGRAPH
.
/* Registering User Files */ %em_register(key=MODEL, type=DATA); %em_register(key=IMPORTANCE, type=DATA); %em_register(key=NODES, type=DATA); %em_register(key=LEAFSTATS, type=DATA); /* Training Decision Tree Model */ %em_arbor( criterion=probchisq, alpha=0.2, outmodel=&EM_USER_MODEL, outimport=&EM_USER_IMPORTANCE, outnodes=&EM_USER_NODES); /**************************************************************************/ /* CRITERION = criterion (VARIANCE, PROBF, ENTROPY, GINI, PROBCHISQ) */ /* ALPHA = alpha value; used with criterion = PROBCHISQ or PROBF */ /* (default=0.20) */ /* OUTMODEL = tree data set; encode info used in the INMODEL option */ /* OUTIMPORT = importance data set; contains variable importance */ /* OUTNODES = nodes data set; contains node information */ /**************************************************************************/ /* Modifying Exported Metadata */ data _null_; length string $200; filename X "&EM_FILE_CDELTA_TRAIN"; file X; set &EM_USER_IMPORTANCE end=eof; if IMPORTANCE =0 then do; string = 'if NAME="'!!trim(left(name))!!'" then do;'; put string; put 'ROLE="REJECTED";'; string = 'COMMENT="'!!"&EM_NODEID"!!':Rejected because of low importance value";'; put string; put 'end;'; end; else do; string = 'if NAME="'!!trim(left(name))!!'" then ROLE="INPUT";'; put string; end; if ^eof then put 'else'; run;
/* Generating Reports */ /* Initialize &EM_PRED with the name of the */ /* target=1 prediction variable */ data _null_; set &em_dec_decmeta; where _TYPE_ eq "PREDICTED" AND LEVEL eq "GOOD"; call symput("EM_PRED",VARIABLE); run; /* Reinitialize registered keys */ %em_getname(key=LEAFSTATS, type=data); %em_getname(key=NODES, type=data); %em_getname(key=IMPORTANCE, type=data); /* retrieve the predicted variables data set */ data &EM_USER_LEAFSTATS; set &EM_USER_NODES( keep=LEAF N NPRIORS P_: I_: U_:); where LEAF ne .; format LEAF 3.; run; /* plot the target prediction for each leaf */ %EM_REPORT(key=LEAFSTATS, description=STATISTICS, viewtype=BAR, freq=&EM_PRED, x=LEAF); /* Generating Graphs */ %em_getname(key=IMPORTANCE, type=data); /* Plot the Importance of the Individual Variables */ proc gchart data=&EM_USER_IMPORTANCE; vbar name/sumvar=importance discrete descending; title 'Variable Importance'; run; title; quit;
%em_register(type=Data, key=Example);
data &em_user_Example; set &em_import_Data; run;
%em_report( key=Example, viewtype=Bar, x=Reason, autodisplay=Y, description=%bquote(Simple Bar Chart), block=%bquote(My Graphs));
%em_report( key=Example, viewtype=Bar, x=Reason, group=Job, autodisplay=Y, description=%bquote(REASON grouped by JOB), block=%bquote(My Graphs));
%em_report( key=example, viewtype=Bar, x=Reason, group=Job, freq=Loan, autodisplay=Y, description=%bquote(REASON grouped by JOB weighted by LOAN), block=%bquote(My Graphs));
%em_register(type=Data, key=Example); data &em_user_Example; set &em_import_data; run; %em_report( key=Example, viewtype=Bar, view=1, x=Reason, group=Job, freq=Loan, choicetext=Loan, autodisplay=Y, description=%bquote(Reason by Job with Weights), block=%bquote(My Graphs)); %em_report( view=1, freq=Value, choicetext=Value); %em_report( view=1, freq=Mortdue, choicetext=Mortdue);
%em_register(type=Data, key=Sample); /* Simulate the data */ data &em_user_Sample; do X=1 to 100; var1 = 10 + ranuni(1234)*2; var2 = 10 + rannor(1234)*2; var3 = 10 + rannor(1234)*2.5; output; end; run ; %em_report( key=Sample, viewtype=Lineplot, view=2, x=X, /* specify the x-axis variable */ y1=var1, /* specify the 1st y-axis variable */ y2=var2, /* specify the 2nd y-axis variable */ choicetext=FirstFrame, autodisplay=Y, description=%bquote(Line Plots), block=%bquote(My Graphs)); %em_report( view=2, y1=var2, y2=var3, choicetext=SecondFrame);
%em_register(key=Outtree, type=Data); %em_getname(key=Outtree, type=Data); proc varclus data = &em_import_data hi outtree=&em_user_Outtree; var Clage Clno Debtinc Delinq Derog Loan Mortdue Ninq Value Yoj; run; %em_report( key=OUTTREE, viewtype=DENDROGRAM, autodisplay=Y, block=Dendrogram, name=_Name_, parent=_Parent_, height=_Varexp_);
%em_register(key=Data, type=Data); /* simulate data */ data One; do i = 1 to 100; x= ranuni(0) * 100 * 200; y = ranuni(0) * 100 + 75; z = ranuni(0) * 100 + 10; output; end; run; data &em_user_data; set Work.One; run; /* K-Dimensional Scatter Plot */ %em_report( key=Data, viewtype=ThreeDScatter, x=X, y=Y, z=Z, block=%bquote(My Graphs), description=%bquote(3DScatterPlot), autodisplay=Y); /* K-Dimensional Surface Plot */ %em_report( key=Data, viewtype=Surface, x=X, y=Y, z=Z, block=%bquote(My Graphs), description=%bquote(Surface), autodisplay=Y); %em_register(key=Class, type=Data); data &em_user_Class; set Sashelp.Class; run; /* K-Dimensional Bar Chart */ %em_report( key=Class, viewtype=ThreeDBar, x=Name, y=Weight, series=Age, block=%bquote(My Graphs), description=%bquote(3DBar), autodisplay=Y);
%em_register(type=Data, key=Example); data &em_user_Example; set &em_import_data; where (Job='ProfExe' or Job='Mgr') and (Reason = 'DebtCon' or Reason = 'HomeImp'); run; %em_report( key=Example, viewtype=Lattice, latticetype=Scatter, x=Debtinc, y=Mortdue, latticex=Job, latticey=Reason);
%em_register(key=A, type=DATA); %em_register(key=B, type=DATA); data &em_user_a; set &em_lib..assoc_links; run; data &em_user_b; set &em_lib..assoc_nodes; run; %em_report(viewtype=Constellation, linkkey=A, nodekey=B, LINKFROM=FROM, LINKTO=TO, LINKID=linkid, LINKVALUE=CONF, nodeid=item, nodesize=count, nodetip=item);
%em_register(key=REPORT, type=FILE, extension=pdf); %em_report(KEY=REPORT, BLOCK=MODEL, VIEWTYPE = FILEVIEWER, autodisplay=Y, DESCRIPTION=My Custom Document); ods pdf file=""; /* your sgplot code goes here */ ods pdf close;
/* your sgplot code goes here */
.
You need to insert your specific PROC SGPLOT code at that point in
the code.
C:\Project\test\Workspaces\EMWS7\EMCODE\report.pdf
,
which maps to the project, workspace, code node ID, and file reference
for the PDF.
ODS
PDF
statement uses a macro variable created by the %EM_REGISTER
macro called &EM_USER_REPORT to write the PDF file in the desired
location. Here, the term report
in this macro
variable is the same as the KEY= value in the &EM_REGISTER macro
invocation.