BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tom_evans_79
Fluorite | Level 6

I have an Enterprise Miner diagram which does the following: Inputs a dataset -> Partitions into training and validation -> Groups variables using Interactive Grouping -> Creates a credit Scorecard -> Scores up the dataset with the Score node -> Creates a custom report in a SAS Code node.

 

In the last node (SAS Code), I will calculate various statistics, but essentially I need to output a frequency table for grouped variables, using the group labels created by the Interactive Grouping node. The question is how I access those labels.

 

To illustrate, here's a very simple piece of code that I could use in the SAS Code node:

proc freq data=&EM_IMPORT_DATA;
	table GRP_age / norow nocol nopercent nocum missing;
run;

The variable 'GRP_age' is created by the Score node using the grouping definitions from Interactive Grouping, and is derived from the input variable 'age'.

 

This creates the following result:

 

GRP_age Frequency
--------------------
1        755
2       1190
3       1302
4       1580
5       1100
6        643

 

...but I would like to see this:

 

Group Name        Frequency
----------------------------

age< 32, _MISSING_      755
32<= age< 40           1190
40<= age< 47           1302
47<= age< 56           1580
56<= age< 65           1100
65<= age                643

 

Guessing I need to merge in a table from the IG node. Any ideas what this other table is called (in a way that will work if I connect my SAS Code node to a new Interactive Grouping node)?

 

Thanks!

 

Tom.

1 ACCEPTED SOLUTION

Accepted Solutions
tom_evans_79
Fluorite | Level 6

Here's an answer to my own question.

 

The following code can be used as part of a SAS Code Node. It accesses the interactive grouping labels that are produced by a preceding interactive grouping node, and creates a format for each of the variables that were grouped. The labels can then be accessed by applying the format to the corresponding GRP_ variable.

* Get Interactive Grouping Node ID;
%EM_PATH (nodeid=&em_nodeid. , outds=all_nodes , nodes=PATH);
data ign_node;
	set all_nodes (where=(component="IGN"));
run;
data ign_node;
	set ign_node;
	by component;
	if last.component;
run;
proc sql;
	select nodelabel into :ign_nodeid from ign_node;
quit;

* Create formats from the data table. The _Z is to avoid invalid formats ending in numbers;
proc sql;
create table fmt_input as
	select compress("F_"||substrn(_grp_variable_,5,100)||"_Z") as fmtname,
          _group_ as start, 
          _label_ as label
	from &em_lib..%sysfunc(cats(%CMPRES(&ign_nodeid.),_stats))  a
       left join &em_lib..%sysfunc(cats(%CMPRES(&ign_nodeid.),_varmappings))  b on b._variable_ = a.display_var
    where a.display_var is not null	   
	;
quit;
PROC FORMAT CNTLIN=fmt_input; 


* Test code something like this;
data test;
    set &em_import_data. (obs=20);
    label_myvar = put(GRP_myvar,F_myvar_Z.);  
run;
proc print data=test;
    var GRP_myvar label_myvar;
run;

 

 

 

View solution in original post

1 REPLY 1
tom_evans_79
Fluorite | Level 6

Here's an answer to my own question.

 

The following code can be used as part of a SAS Code Node. It accesses the interactive grouping labels that are produced by a preceding interactive grouping node, and creates a format for each of the variables that were grouped. The labels can then be accessed by applying the format to the corresponding GRP_ variable.

* Get Interactive Grouping Node ID;
%EM_PATH (nodeid=&em_nodeid. , outds=all_nodes , nodes=PATH);
data ign_node;
	set all_nodes (where=(component="IGN"));
run;
data ign_node;
	set ign_node;
	by component;
	if last.component;
run;
proc sql;
	select nodelabel into :ign_nodeid from ign_node;
quit;

* Create formats from the data table. The _Z is to avoid invalid formats ending in numbers;
proc sql;
create table fmt_input as
	select compress("F_"||substrn(_grp_variable_,5,100)||"_Z") as fmtname,
          _group_ as start, 
          _label_ as label
	from &em_lib..%sysfunc(cats(%CMPRES(&ign_nodeid.),_stats))  a
       left join &em_lib..%sysfunc(cats(%CMPRES(&ign_nodeid.),_varmappings))  b on b._variable_ = a.display_var
    where a.display_var is not null	   
	;
quit;
PROC FORMAT CNTLIN=fmt_input; 


* Test code something like this;
data test;
    set &em_import_data. (obs=20);
    label_myvar = put(GRP_myvar,F_myvar_Z.);  
run;
proc print data=test;
    var GRP_myvar label_myvar;
run;

 

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 667 views
  • 0 likes
  • 1 in conversation