<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Macro Loop Can't Resolve First Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-Can-t-Resolve-First-Variable/m-p/280816#M56814</link>
    <description>&lt;P&gt;Put a QUIT statement to end the PROC SQL step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc Sql; Delete From Result_Append; QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The problem is that PROC SQL is an interactive procedure. Therefore it is still running when the ODS OUTPUT statement is &amp;nbsp;encountered, which leads to the error. &amp;nbsp;For more information about ODS statements and interactive procedures, see &lt;A href="http://blogs.sas.com/content/iml/2011/12/12/sas-tip-put-ods-statements-inside-procedures.html" target="_self"&gt;"SAS Tip: Put ODS statements inside procedures."&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jun 2016 15:00:20 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2016-06-28T15:00:20Z</dc:date>
    <item>
      <title>Macro Loop Can't Resolve First Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-Can-t-Resolve-First-Variable/m-p/280803#M56808</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I posted the following code for another question&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Proc-Logistic-How-to-Pull-Specific-Statistical-Values/m-p/278361#M58881" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Proc-Logistic-How-to-Pull-Specific-Statistical-Values/m-p/278361#M58881&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;,thanks to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS﻿&lt;/a&gt;&amp;nbsp;I solved that Discussion. In that discussion, I realized I'm getting some errors&lt;/P&gt;&lt;P&gt;I just don't understand even though&amp;nbsp;macro resolves Variable3 and Variable4 why it doesn't resolve the Variable1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help me that how can I build proper structure?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you execute the code you can see the errors in the log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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_&amp;amp;Var. Association=Roc_&amp;amp;Var. ParameterEstimates=Err_&amp;amp;Var.;
PROC LOGISTIC DATA=Have NameLen=32 PLOTS(ONLY)=ALL;
MODEL Target (Event = '1')=&amp;amp;Var. /SELECTION=NONE LINK=LOGIT;
RUN;
QUIT;
Ods Output Close; 


Data Err2_&amp;amp;Var.(Keep=Variable StdErr Dataset Rename=(StdErr=Variable2));
Length Dataset $ 32;
Set Err_&amp;amp;Var.;
Where Variable="&amp;amp;Var.";
If Variable="&amp;amp;Var." then Variable="StdErr_";
Dataset="&amp;amp;Var.";
Run;

Data Roc2_&amp;amp;Var.(Keep=Label2 nValue2 Dataset Rename=(nValue2=Variable2 Label2=Variable));
Length Dataset $ 32;
Set Roc_&amp;amp;Var.;
IF Label2="Somers' D" Or Label2="c";
If Label2="c" then Label2="Roc_";
If Label2="Somers' D" then Label2="Gini_";
Dataset="&amp;amp;Var.";
Run;

PROC SQL;
Create Table Append_&amp;amp;Var. As 
Select * From Roc2_&amp;amp;Var.
Outer Union Corr 
Select * From Err2_&amp;amp;Var.;
QUIT;

PROC APPEND Base=Result_Append Data=Append_&amp;amp;Var.;
Run;


%Mend Test;

%Macro Test_Loop;
%let i=1;
%do %while(%scan(&amp;amp;Variable.,&amp;amp;i.,%str( ))~=);
%Test(%scan(&amp;amp;Variable.,&amp;amp;i.,%str( )));
%let i=&amp;amp;i.+1;
%end;
%mend;
%Let Variable=Variable1 Variable3 Variable4;


%Fake_Table;
%Test_Loop;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2016 14:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-Can-t-Resolve-First-Variable/m-p/280803#M56808</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2016-06-28T14:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop Can't Resolve First Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-Can-t-Resolve-First-Variable/m-p/280816#M56814</link>
      <description>&lt;P&gt;Put a QUIT statement to end the PROC SQL step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc Sql; Delete From Result_Append; QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The problem is that PROC SQL is an interactive procedure. Therefore it is still running when the ODS OUTPUT statement is &amp;nbsp;encountered, which leads to the error. &amp;nbsp;For more information about ODS statements and interactive procedures, see &lt;A href="http://blogs.sas.com/content/iml/2011/12/12/sas-tip-put-ods-statements-inside-procedures.html" target="_self"&gt;"SAS Tip: Put ODS statements inside procedures."&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2016 15:00:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-Can-t-Resolve-First-Variable/m-p/280816#M56814</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-06-28T15:00:20Z</dc:date>
    </item>
  </channel>
</rss>

