<?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: Issue with macro variables %let in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356400#M274123</link>
    <description>&lt;P&gt;Thanks Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did some adjustment to my code based on all your suggestions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro vars; 
%let outobs=max;
%do i=0  %to 24;
%let b =&amp;amp;i;
%let var1=test1&amp;amp;b;
%let var2=test2t&amp;amp;b;
%let var3=test3&amp;amp;b;
%let var4=test4t&amp;amp;b;
%let var5=test5&amp;amp;b;
%let var6=test6&amp;amp;b;
%let month=period_&amp;amp;b;

proc  sql;
create table &amp;amp;month as	   
select
filler5
,&amp;amp;var1
,&amp;amp;var2
,&amp;amp;var3
,&amp;amp;var4
,&amp;amp;var5
,&amp;amp;var6
,case when &amp;amp;var1&amp;lt;&amp;gt;-16 or &amp;amp;var2&amp;lt;&amp;gt;-16
or &amp;amp;var3&amp;lt;&amp;gt;-16 or &amp;amp;var4&amp;lt;&amp;gt;-16 or &amp;amp;var5 is not null then 1 else 0 end as
&amp;amp;month

from SAS_Out.&amp;amp;Data_Out
WHERE a='x';
;
run;
%end;
run;

%mend vars;
%vars;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And it worked perfectly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An now can you understand what I am tryng to do??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks Again all&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;JC&lt;/P&gt;</description>
    <pubDate>Fri, 05 May 2017 14:28:52 GMT</pubDate>
    <dc:creator>Jcorti</dc:creator>
    <dc:date>2017-05-05T14:28:52Z</dc:date>
    <item>
      <title>Issue with macro variables %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356363#M274117</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting an issue when I am delcaring macro variables,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
%let %do i=0 %to 24;

%let var1=a&amp;amp;i;
%let var2=b&amp;amp;i;
%let var3=c&amp;amp;i;
%let var4=d&amp;amp;i;
%let var5=e&amp;amp;i;
%let month=period&amp;amp;i;
output;
%end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is the error;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone can Help me on this??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot in advance&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 13:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356363#M274117</guid>
      <dc:creator>Jcorti</dc:creator>
      <dc:date>2017-05-05T13:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with macro variables %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356368#M274118</link>
      <description>&lt;P&gt;You are trying to use macro language without knowing basic concepts:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;What should a %LET statement look like&lt;/LI&gt;
&lt;LI&gt;When is a %DO statement permissible&lt;/LI&gt;
&lt;LI&gt;What is the relationship between macro language and SAS language&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;If you describe what you are trying to accomplish, you can get answers to a specific question. &amp;nbsp;But the studying part is up to you.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 13:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356368#M274118</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-05-05T13:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with macro variables %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356369#M274119</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What should the output dataset test look like ?&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 13:24:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356369#M274119</guid>
      <dc:creator>robert215</dc:creator>
      <dc:date>2017-05-05T13:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with macro variables %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356373#M274120</link>
      <description>&lt;P&gt;Well, You simply cannot declare two macro statements in one i.e %let and %do, these are 2 independent exclusive&amp;nbsp;statements. So that's an absolute NO there.&lt;/P&gt;&lt;P&gt;Open code recursion was simply caused by not finding the end of macro statement ; and if often contributed to be known as black hole problem&lt;/P&gt;&lt;P&gt;What is that you want to accomplish?&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 13:28:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356373#M274120</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-05-05T13:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with macro variables %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356374#M274121</link>
      <description>&lt;P&gt;%do is only allowed within a macro definition, and no %let should be done within another %let; Since your %do is within a %let, all other macro statements are considered part of that first %let.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bottom line: start with simple code before turning to complex things. And DO NOT get into macros before you have a thorough grasp of programming as such. The macro language needs a programmer's mindset.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 13:28:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356374#M274121</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-05T13:28:44Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with macro variables %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356379#M274122</link>
      <description>&lt;P&gt;The problem is with the %end. &amp;nbsp;Macro language should always be encased within %macro and %mend statements such as:&lt;/P&gt;
&lt;PRE&gt;%macro tmp();
  %if a=b %then %do;
    ..
  %end;
%mend tmp;&lt;/PRE&gt;
&lt;P&gt;Secondly, why do you have a load of %let statements in a datastep? &amp;nbsp;Macro is nothing to do with Base SAS - which is the lanaguage. &amp;nbsp;Put your %let statements at the top of the code, they are only there for find/replace. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your second problem is this statments:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt; i&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%to&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;24&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Macro do loops are not define with %let.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 13:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356379#M274122</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-05T13:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with macro variables %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356400#M274123</link>
      <description>&lt;P&gt;Thanks Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did some adjustment to my code based on all your suggestions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro vars; 
%let outobs=max;
%do i=0  %to 24;
%let b =&amp;amp;i;
%let var1=test1&amp;amp;b;
%let var2=test2t&amp;amp;b;
%let var3=test3&amp;amp;b;
%let var4=test4t&amp;amp;b;
%let var5=test5&amp;amp;b;
%let var6=test6&amp;amp;b;
%let month=period_&amp;amp;b;

proc  sql;
create table &amp;amp;month as	   
select
filler5
,&amp;amp;var1
,&amp;amp;var2
,&amp;amp;var3
,&amp;amp;var4
,&amp;amp;var5
,&amp;amp;var6
,case when &amp;amp;var1&amp;lt;&amp;gt;-16 or &amp;amp;var2&amp;lt;&amp;gt;-16
or &amp;amp;var3&amp;lt;&amp;gt;-16 or &amp;amp;var4&amp;lt;&amp;gt;-16 or &amp;amp;var5 is not null then 1 else 0 end as
&amp;amp;month

from SAS_Out.&amp;amp;Data_Out
WHERE a='x';
;
run;
%end;
run;

%mend vars;
%vars;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And it worked perfectly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An now can you understand what I am tryng to do??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks Again all&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;JC&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 14:28:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356400#M274123</guid>
      <dc:creator>Jcorti</dc:creator>
      <dc:date>2017-05-05T14:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with macro variables %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356406#M274124</link>
      <description>&lt;P&gt;Quite frankly no. &amp;nbsp;You appear to be creating 24 datasets, for no reason. &amp;nbsp;You have a call to a macro variable &amp;amp;data_out never defined, and you refer to a variable A in your proc sql which is not selected, and the same across all datasets.&lt;/P&gt;
&lt;P&gt;This can all be done in one dataset, and have a variable called period which goes from 1-24, this will make your programming far easier in the long run:&lt;/P&gt;
&lt;PRE&gt;data want;
  do period=1 to 24;
    set sas_out.&amp;amp;data_out.;
    if ...;
    output;
  end;
run;
  &lt;/PRE&gt;
&lt;P&gt;However it is impossible to say without seeing some test data (form of a datastep) and what the output should look like - other than one dataset would be better than many.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 14:35:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-macro-variables-let/m-p/356406#M274124</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-05T14:35:23Z</dc:date>
    </item>
  </channel>
</rss>

