<?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: SAS Macro error in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-Macro-error/m-p/880201#M43109</link>
    <description>&lt;P&gt;If the goal is to generate CODE from the metadata in the dataset&amp;nbsp;&lt;SPAN&gt;A then it might be easier to do that by just writing the code directly from the dataset and skipping the macro variable.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  file code ;
  set a;
  where not (index(length,'$') or upcase(var1)='NOTAVAILABLE');
  if upcase(var1)='INTEGER' then var1=1;
  put var2 '=round(' var2 ',' var1 ');' ;
run;

data test;
  set b;
%include code / source2 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;1940  data test;
1941    set b;
1942  %include code / source2 ;
NOTE: %INCLUDE (level 1) file CODE is (system-specific pathname).
1943 +Age =round(Age ,1 );
1944 +Score1 =round(Score1 ,0.0001 );
1945 +Score2 =round(Score2 ,1 );
1946 +Score_3 =round(Score_3 ,0.00001 );
NOTE: %INCLUDE (level 1) ending.
1947  run;

NOTE: The data set WORK.TEST has 6 observations and 9 variables.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;PS You seem to be trying to use INFORMAT and FORMAT as if they were designed to DEFINE variables.&amp;nbsp; That is not what those statements are for. The only reason they work in your code is because it is the first place the variable is mentioned so the data step compiler is forced to &lt;STRONG&gt;GUESS&lt;/STRONG&gt; that you wanted the &lt;STRONG&gt;LENGTH&lt;/STRONG&gt; of the variable to be defined to match the &lt;STRONG&gt;WIDTH&lt;/STRONG&gt; of the informat or format that you wanted to attach to it.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Jun 2023 13:02:02 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-06-12T13:02:02Z</dc:date>
    <item>
      <title>SAS Macro error</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-Macro-error/m-p/880153#M43106</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I am trying to round multiple variables from below dataset B. Dataset A is my reference dataset with rounding requirements for decimal places. Below in this dummy data I have less number of variables but in real data there are many variables, the following code works as expected for less variables but for lot of variables I am getting the below error:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#993300"&gt;ERROR: The length of the value of the macro variable LGT_MACRO (65540) exceeds the maximum length (65534). The value has been &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;truncated to 65534 characters.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#993300"&gt;Can someone please help me fixing&amp;nbsp; the above error.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example&amp;nbsp; datasets are below&lt;/P&gt;&lt;P&gt;/*Dataset A:*/&lt;BR /&gt;/*If not an integer then round to number of decimal places from Var1 column*/&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;informat var1 $50. length $10. var2 $200.;&lt;BR /&gt;infile datalines delimiter=',';&lt;BR /&gt;input var1 length var2 ;&lt;/P&gt;&lt;P&gt;datalines;&lt;BR /&gt;NotAvailable,8,Subject&lt;BR /&gt;NotAvailable,8,Site&lt;BR /&gt;NotAvailable,$200,Visit&lt;BR /&gt;integer,8,Age&lt;BR /&gt;0.0001,8,Score1&lt;BR /&gt;integer,8,Score2&lt;BR /&gt;NotAvailable,$200,Date&lt;BR /&gt;0.00001,8,Score_3&lt;BR /&gt;NotAvailable,$200,I_am_the_longest_variable_Test_3&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*dataset B:*/&lt;BR /&gt;data b;&lt;BR /&gt;informat Visit $200. Date $200. I_am_the_longest_variable_Test_3 $200.;&lt;BR /&gt;infile datalines delimiter=',';&lt;BR /&gt;input Subject Site Visit Age Score1 Score2 Date Score_3 I_am_the_longest_variable_Test_3 ;&lt;/P&gt;&lt;P&gt;datalines;&lt;BR /&gt;1234,001,Day1,55,344.70452025162167,4,2023-06-08 15:37,4.5707963267948966,ABCD&lt;BR /&gt;2456,002,Day5,45,100.12342025162167,3,2023-06-09 15:37,3.1234907586284892,WXYZ&lt;BR /&gt;3456,003,Day1,60,94.38627492995121,2,2023-06-10 15:37,5.7398282916662683,ABCD&lt;BR /&gt;7890,001,Day5,52,92.28219778353588,1,2023-06-08 15:37,3.749207747474,WXYZ&lt;BR /&gt;1111,002,Day1,70,124.6789456782671,3,2023-06-09 15:37,4.172819191919191,ABCD&lt;BR /&gt;1567,003,Day1,59,125.4796290763492,5,2023-06-10 15:37,1.272383939999,WXYZ&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data a1;&lt;BR /&gt;set a;&lt;BR /&gt;if index(length,'$')&amp;gt;0 or UPCASE(var1)='NOTAVAILABLE' then ;&lt;BR /&gt;else if UPCASE(var1)='INTEGER' then Rnd_var=0;&lt;BR /&gt;else If UPCASE(var1)='0.0001' then Rnd_var=0.0001;&lt;BR /&gt;else If UPCASE(var1)='0.00001' then Rnd_var=0.00001;&lt;BR /&gt;else If UPCASE(var1)='NOTAVAILABLE' then Rnd_var=.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data sample_formats;&lt;BR /&gt;set a1;&lt;BR /&gt;format length_macr0 $100. ;&lt;BR /&gt;if index(length,'$')&amp;gt; 0 or UPCASE(var1) in ('NOTAVAILABLE') then length_macr0='';&lt;BR /&gt;else length_macr0=cat(compress(var2),'=','round(',compress(var2),',',compress(rnd_var),')') ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;select length_macr0 into :lgt_macro separated by ";"&lt;BR /&gt;from sample_formats&lt;BR /&gt;where length_macr0 is not missing&lt;BR /&gt;;&lt;BR /&gt;%put length_macr0;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;set b;&lt;BR /&gt;&amp;amp;lgt_macro. ;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2023 10:25:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-Macro-error/m-p/880153#M43106</guid>
      <dc:creator>Aidaan_10</dc:creator>
      <dc:date>2023-06-12T10:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro error</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-Macro-error/m-p/880156#M43107</link>
      <description>&lt;P&gt;this part:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select &lt;STRONG&gt;length_macr0 into :lgt_macro separated by ";"&lt;/STRONG&gt;
from sample_formats
where length_macr0 is not missing
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;causes the problem, the data extracted in the &lt;CODE class=" language-sas"&gt;&lt;STRONG&gt;length_macr0&lt;/STRONG&gt;&lt;/CODE&gt;&amp;nbsp;variable is bigger than possible macrovariable length.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you can do 2 things:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) make it:&amp;nbsp;&lt;CODE class=" language-sas"&gt;select STRIP(&lt;STRONG&gt;length_macr0) into :lgt_macro separated by ";"&lt;/STRONG&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;2) create a macrovariable list:&amp;nbsp;&lt;CODE class=" language-sas"&gt;select &lt;STRONG&gt;length_macr0 into :lgt_macro1- &lt;/STRONG&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;and when the list is created call to its elements like:&amp;nbsp;&lt;CODE class=" language-sas"&gt;&lt;STRONG&gt;&amp;amp;&amp;amp;lgt_macro%i&lt;/STRONG&gt;&lt;/CODE&gt; where the "i" is macro %do-loop iterator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2023 10:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-Macro-error/m-p/880156#M43107</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-06-12T10:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro error</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-Macro-error/m-p/880201#M43109</link>
      <description>&lt;P&gt;If the goal is to generate CODE from the metadata in the dataset&amp;nbsp;&lt;SPAN&gt;A then it might be easier to do that by just writing the code directly from the dataset and skipping the macro variable.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  file code ;
  set a;
  where not (index(length,'$') or upcase(var1)='NOTAVAILABLE');
  if upcase(var1)='INTEGER' then var1=1;
  put var2 '=round(' var2 ',' var1 ');' ;
run;

data test;
  set b;
%include code / source2 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;1940  data test;
1941    set b;
1942  %include code / source2 ;
NOTE: %INCLUDE (level 1) file CODE is (system-specific pathname).
1943 +Age =round(Age ,1 );
1944 +Score1 =round(Score1 ,0.0001 );
1945 +Score2 =round(Score2 ,1 );
1946 +Score_3 =round(Score_3 ,0.00001 );
NOTE: %INCLUDE (level 1) ending.
1947  run;

NOTE: The data set WORK.TEST has 6 observations and 9 variables.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;PS You seem to be trying to use INFORMAT and FORMAT as if they were designed to DEFINE variables.&amp;nbsp; That is not what those statements are for. The only reason they work in your code is because it is the first place the variable is mentioned so the data step compiler is forced to &lt;STRONG&gt;GUESS&lt;/STRONG&gt; that you wanted the &lt;STRONG&gt;LENGTH&lt;/STRONG&gt; of the variable to be defined to match the &lt;STRONG&gt;WIDTH&lt;/STRONG&gt; of the informat or format that you wanted to attach to it.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2023 13:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-Macro-error/m-p/880201#M43109</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-12T13:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro error</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-Macro-error/m-p/880231#M43114</link>
      <description>&lt;P&gt;More than a little concerned about reading any DATE type value as $200 to begin with. SAS dates should generally be date, time or datetime valued with an appropriate format though the values should be integer unless dealing with fractional seconds.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2023 15:41:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-Macro-error/m-p/880231#M43114</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-06-12T15:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro error</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-Macro-error/m-p/880258#M43118</link>
      <description>&lt;P&gt;Thanks Tom...this worked.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2023 17:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-Macro-error/m-p/880258#M43118</guid>
      <dc:creator>Aidaan_10</dc:creator>
      <dc:date>2023-06-12T17:19:32Z</dc:date>
    </item>
  </channel>
</rss>

