<?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 variable resolution in Advanced Programming</title>
    <link>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/699163#M16</link>
    <description>&lt;P&gt;Thank you all &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Makes more sense now&lt;/P&gt;</description>
    <pubDate>Mon, 16 Nov 2020 14:44:33 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2020-11-16T14:44:33Z</dc:date>
    <item>
      <title>Macro variable resolution</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698105#M7</link>
      <description>&lt;P&gt;Hi all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone help me understand and resolve this problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   do x = 1 to 10000;
      output;
   end;
run;

proc sql noprint;
   select x into :x1 -
   from have;
   %let t = &amp;amp;sqlobs.;
quit;

%put &amp;amp;x1.;
%put &amp;amp;x10000.;

%macro m;
   %do i=1 %to &amp;amp;t.;
      &amp;amp;&amp;amp;x&amp;amp;i
   %end;
%mend;

%put %m;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This gives me quite a lot of the error message below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;"ERROR: The text expression length (65545) exceeds maximum length (65534). The text expression has&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;been truncated to 65534 characters."&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why does this happen? Works fine with less macro variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is purely for my own understanding, I am well aware that one should not create this many macro variables (as I'm sure&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;will remind me &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 10:37:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698105#M7</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-11T10:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698114#M8</link>
      <description>&lt;P&gt;It's a function style macro, it returns a string that is too long ...&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 11:07:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698114#M8</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-11T11:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698115#M9</link>
      <description>&lt;P&gt;Ok, so this is not because the individual macro variables are two long?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How would I resolve this problem?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 11:10:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698115#M9</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-11T11:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698117#M10</link>
      <description>&lt;P&gt;It is not a problem of the macro, it is a problem of %PUT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   do x = 1 to 10000;
      output;
   end;
run;

proc sql noprint;
   select x into :x1 -
   from have;
   %let t = &amp;amp;sqlobs.;
quit;

%put &amp;amp;x1.;
%put &amp;amp;x10000.;

%macro m;
   %do i=1 %to &amp;amp;t.;
      x&amp;amp;&amp;amp;x&amp;amp;i. = 0;
   %end;
%mend;

data test;
%m
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Runs without problems and creates a dataset with 10000 variables.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 11:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698117#M10</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-11T11:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698120#M11</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Ok, so this is not because the individual macro variables are two long?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How would I resolve this problem?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What resolution do you want?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 11:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698120#M11</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-11T11:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698127#M12</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The %put instruction will not accept a string that is more than 65534 characters long&lt;/P&gt;
&lt;P&gt;whether is is generated by a macro, macrovariables or typed on the keyboard.&lt;/P&gt;
&lt;P&gt;If by "resolving the problem" you mean displaying a longer string in the log you can&lt;/P&gt;
&lt;P&gt;use the '@' character in a data step put statements :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
do i=1 to 70000;
put '1'@;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Nov 2020 11:54:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698127#M12</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2020-11-11T11:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698133#M13</link>
      <description>&lt;P&gt;The problem originates within PROC SQL.&amp;nbsp; It is creating individual macro variables that are longer than you expect.&amp;nbsp; You can easily see this by running:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put *&amp;amp;x1*;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since macro variables contain text strings, and all the X values are numeric, this statement forces SQL to perform numeric to character conversions:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   select x into :x1 -
   from have;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Unlike a DATA step, SQL doesn't issue a note in the log about the conversions.&amp;nbsp; To alleviate the problem, you can try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   select strip(put(x,best8.)) into :x1 -
   from have;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course the size limit for macro variables still exists.&amp;nbsp; But you don't have to be hitting it with only 10000 integers.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 12:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698133#M13</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-11-11T12:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698145#M14</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can save a lot of white space by omitting what was likely meant as "code indentation":&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#999999"&gt;%macro m;
   %do i=1 %to &amp;amp;t.;&lt;/FONT&gt;
&lt;STRONG&gt;&amp;amp;&amp;amp;x&amp;amp;i&lt;/STRONG&gt;
&lt;FONT color="#999999"&gt;   %end;
%mend;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;The values are now separated by single blanks (rather than seven blanks) in &lt;FONT face="courier new,courier"&gt;%m&lt;/FONT&gt;, which gets you far below the 65534-character limit and thus avoids the error messages.&lt;/P&gt;
&lt;PRE&gt;129  %put %length(%m);
48893&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Nov 2020 13:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698145#M14</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-11-11T13:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698146#M15</link>
      <description>&lt;P&gt;If you use the :var1- syntax to generate multiple macro variables the values are automatically trimmed.&lt;/P&gt;
&lt;P&gt;To impact the format used to convert a number into the string stored in the macro variable you can just change the format attached to the variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select name,age format=z5. into :n1-,:a1- from sashelp.class;
quit;
%put |&amp;amp;n1|&amp;amp;a1| ;
%put |&amp;amp;n2|&amp;amp;a2| ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;742   %put |&amp;amp;n1|&amp;amp;a1| ;
|Alfred|00014|
743   %put |&amp;amp;n2|&amp;amp;a2| ;
|Alice|00013|&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 13:49:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/698146#M15</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-11T13:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/699163#M16</link>
      <description>&lt;P&gt;Thank you all &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Makes more sense now&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 14:44:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/Macro-variable-resolution/m-p/699163#M16</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-16T14:44:33Z</dc:date>
    </item>
  </channel>
</rss>

