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

 

Hello everyone,

 

I’m trying to pull “Stand Error”, “Gini” and “Roc” Values for more than one variable by using PROC LOGISTIC. Actually, I could pull them by the help of following code. At this point, I would like to ask that is there any method to pull this values without using much data steps.

 

My sample code as below;

 

Data Have;
Length Target 8 Variable2 8 Variable3 8 Variable4 8 ;
Infile Datalines Missover;
Input Target Variable2 Variable3 Variable4 ;
Datalines;
0 -0.435409602 0.1111702173 -0.375361259
0 -0.435409602 0.9767642068 -0.375361259
1 -0.435409602 0.9767642068 -0.375361259
0 -0.435409602 0.9767642068 -0.375361259
0  0.8432328141 0.9767642068 -0.566274869
1 -0.435409602 0.9767642068 0.5257570782
0 -0.202340531 0 0.5257570782
0 -0.435409602 0 0.5257570782
1 0.3610487663 -1.119484453 0.5257570782
1 0 0 0.1876969043
0 -0.435409602 -0.82913977 -0.566274869
0 -0.435409602 -0.82913977 0.1876969043
1 0.3610487663 0.9767642068 -0.199600942
0 0.8432328141 0 -0.199600942
0 -0.202340531 0.9767642068 -0.375361259
;
Run;

%Macro Fake_Table;
Data Result_Append;
Length Dataset $ 32 Variable $ 9 Variable2 8;
Run;
Proc Sql; Delete From Result_Append;
%Mend Fake_Table;


%Macro Test(Var);

Ods Graphics On; 
Ods Output ResponseProfile=Res_&Var. Association=Roc_&Var. ParameterEstimates=Err_&Var.;
PROC LOGISTIC DATA=Have NameLen=32 PLOTS(ONLY)=ALL;
MODEL Target (Event = '1')=&Var. /SELECTION=NONE LINK=LOGIT;
RUN;
QUIT;

Data Err2_&Var.(Keep=Variable StdErr Dataset Rename=(StdErr=Variable2));
Length Dataset $ 32;
Set Err_&Var.;
Where Variable="&Var.";
If Variable="&Var." then Variable="StdErr_";
Dataset="&Var.";
Run;

Data Roc2_&Var.(Keep=Label2 nValue2 Dataset Rename=(nValue2=Variable2 Label2=Variable));
Length Dataset $ 32;
Set Roc_&Var.;
IF Label2="Somers' D" Or Label2="c";
If Label2="c" then Label2="Roc_";
If Label2="Somers' D" then Label2="Gini_";
Dataset="&Var.";
Run;

PROC SQL;
Create Table Append_&Var. As 
Select * From Roc2_&Var.
Outer Union Corr 
Select * From Err2_&Var.;
QUIT;

PROC APPEND Base=Result_Append Data=Append_&Var.;
Run;
 
Ods Output Close; 
Ods Graphics Off;

%Mend Test;
%Let Variable=Variable2 Variable3 Variable4;
%Macro Test_Loop;
%let i=1;
%do %while(%scan(&Variable.,&i.,%str( ))~=);
%Test(%scan(&Variable.,&i.,%str( )));
%let i=&i.+1;
%end;
%mend;



%Fake_Table;
%Test_Loop;



 

 

Result_Append gives my desired output,

 

Thank you,

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

I think your analysis will be cleaner and simpler if you convert the data from "Wide form" to "long form." That will enable you to use a BY statement, rather than a macro loop, to repeat the analysis for each model that has a single independent variable.  For example, try modifying something like this:

 

data Want;
set Have;
Group=1; X=Variable2; output;
Group=2; X=Variable3; output;
Group=3; X=Variable4; output;
drop Variable2-Variable4;
run;

proc sort data=Want; by Group; run;

PROC LOGISTIC DATA=Want NameLen=32  ...;
BY Group;
MODEL Target (Event = '1')=X / LINK=LOGIT;
RUN;

View solution in original post

7 REPLIES 7
Rick_SAS
SAS Super FREQ

I think your analysis will be cleaner and simpler if you convert the data from "Wide form" to "long form." That will enable you to use a BY statement, rather than a macro loop, to repeat the analysis for each model that has a single independent variable.  For example, try modifying something like this:

 

data Want;
set Have;
Group=1; X=Variable2; output;
Group=2; X=Variable3; output;
Group=3; X=Variable4; output;
drop Variable2-Variable4;
run;

proc sort data=Want; by Group; run;

PROC LOGISTIC DATA=Want NameLen=32  ...;
BY Group;
MODEL Target (Event = '1')=X / LINK=LOGIT;
RUN;
ertr
Quartz | Level 8

Hello @Rick_SAS,

 

Thank you for providing this sample code, I think it sould seem as below;

 

Ods Graphics On; 
Ods Output ResponseProfile=Res_ Association=Roc_ ParameterEstimates=Err_;

PROC LOGISTIC DATA=Want NameLen=32  PLOTS(ONLY)=ALL;
BY Group;
MODEL Target (Event = '1')=X / LINK=LOGIT;
RUN;

Ods Output Close; 
Ods Graphics Off;


Data Err2_ (Keep=Group Variable StdErr Dataset Rename=(StdErr=Variable2));
Length Dataset $ 32;
Set Err_;
Where Variable="X";
If Variable="X" then Variable="StdErr_";
Dataset="X";
Run;

Data Roc2_(Keep=Dataset Group Label2 nValue2  Rename=(nValue2=Variable2 Label2=Variable));
Length Dataset $ 32;
Set Roc_;
IF Label2="Somers' D" Or Label2="c";
If Label2="c" then Label2="Roc_";
If Label2="Somers' D" then Label2="Gini_";
Dataset="X";
Run;

PROC SQL;
Create Table Append_ As 
Select * From Roc2_
Outer Union Corr 
Select * From Err2_;
QUIT;

PROC SORT Data=Append_;
By Group;
Run;

 

By the way, when I first put my sample code, I didn't face an error but I re-wrote my previous sample code in my Pc,and now, I'm getting following errors, do you have an idea?


ERROR: File WORK.ERR_VARIABLE2.DATA does not exist.

ERROR: File WORK.ROC_VARIABLE2.DATA does not exist.

 

Thank you,

Rick_SAS
SAS Super FREQ

Regarding the 

ERROR: File WORK.ERR_VARIABLE2.DATA does not exist.

 

You must have code (not shown here) that is referencing that data set name. On one computer you were accessing a stale copy that was created earlier during development. Find out the new name of the data set that contains that info.

ertr
Quartz | Level 8

@Rick_SAS,

 

It is little bir interesting, when I wrote the following code, Variable3 and Variable4 dataset is created, Variable2 is not created.

 

%Macro Test(Var);
 
Ods Graphics On; 
Ods Output ResponseProfile=Res_&Var. Association=Roc_&Var. ParameterEstimates=Err_&Var.;
PROC LOGISTIC DATA=Have NameLen=32 PLOTS(ONLY)=ALL;
MODEL Target (Event = '1')=&Var. /SELECTION=NONE LINK=LOGIT;
RUN;
QUIT;
 
%Mend Test;
 
%Macro Test_Loop;
%let i=1;
%do %while(%scan(&Variable.,&i.,%str( ))~=);
%Test(%scan(&Variable.,&i.,%str( )));
%let i=&i.+1;
%end;
%mend;
%Let Variable=Variable2 Variable3 Variable4;
 
%Test_Loop;
ertr
Quartz | Level 8

Hi again @Ksharp and @Rick_SAS,

 

Can you give me a brief information about how can I solve my following errors.

 

I just don't understand. Macro resolves Variable3 and Variable4 but it doesn't resolve the Variable2

 

ERROR: File WORK.ERR_VARIABLE2.DATA does not exist.

ERROR: File WORK.ROC_VARIABLE2.DATA does not exist.

 

How can I solve the foregoing erros? 

Ksharp
Super User
ods output is a good way to go, also check some output option like :

PROC LOGISTIC DATA=sashelp.class NameLen=32 ;
MODEL sex(Event = 'F')=age height  / LINK=LOGIT outroc=roc influence;
RUN;


ertr
Quartz | Level 8

@Ksharp,

 

Thank you but it sounds a little bit complicated. I just don't get which columns represents what?

 

Thank you,

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1156 views
  • 0 likes
  • 3 in conversation