DATA Step, Macro, Functions and more

Macro Loop Can't Resolve First Variable

Accepted Solution Solved
Reply
Contributor
Posts: 51
Accepted Solution

Macro Loop Can't Resolve First Variable

Hello everyone,

 

I posted the following code for another question

 

(https://communities.sas.com/t5/SAS-Procedures/Proc-Logistic-How-to-Pull-Specific-Statistical-Values/...)

 

,thanks to @Rick_SAS I solved that Discussion. In that discussion, I realized I'm getting some errors

I just don't understand even though macro resolves Variable3 and Variable4 why it doesn't resolve the Variable1.

 

Can someone help me that how can I build proper structure?

 

If you execute the code you can see the errors in the log.

 

 

Data Have;
Length Target 8 Variable1 8 Variable3 8 Variable4 8 ;
Infile Datalines Missover;
Input Target Variable1 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 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;
Ods Output Close; 


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;


%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=Variable1 Variable3 Variable4;


%Fake_Table;
%Test_Loop;

Thank you


Accepted Solutions
Solution
‎06-28-2016 12:17 PM
SAS Super FREQ
Posts: 3,475

Re: Macro Loop Can't Resolve First Variable

Put a QUIT statement to end the PROC SQL step:

 

Proc Sql; Delete From Result_Append; QUIT;

The problem is that PROC SQL is an interactive procedure. Therefore it is still running when the ODS OUTPUT statement is  encountered, which leads to the error.  For more information about ODS statements and interactive procedures, see "SAS Tip: Put ODS statements inside procedures."

View solution in original post


All Replies
Solution
‎06-28-2016 12:17 PM
SAS Super FREQ
Posts: 3,475

Re: Macro Loop Can't Resolve First Variable

Put a QUIT statement to end the PROC SQL step:

 

Proc Sql; Delete From Result_Append; QUIT;

The problem is that PROC SQL is an interactive procedure. Therefore it is still running when the ODS OUTPUT statement is  encountered, which leads to the error.  For more information about ODS statements and interactive procedures, see "SAS Tip: Put ODS statements inside procedures."

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 162 views
  • 2 likes
  • 2 in conversation