<?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 SAS MACROS in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SAS-MACROS/m-p/475661#M71176</link>
    <description>&lt;PRE&gt;%macro icodes ;
	
	proc sql ;
		create table _01_itable2 as
		%do i = 1 %to 14 ;
			select distinct enrolid, dx&amp;amp;i. as code 
			from derived._01_itable 
			%if i &amp;lt;14 %then %do ;
				union
			%end ;
		%end ;
		;
	quit;

%mend icodes ;
%icodes;	&lt;/PRE&gt;&lt;P&gt;Whats wrong with this code ?&lt;/P&gt;&lt;P&gt;SAS is giving me this error :-&amp;nbsp;NOTE: Line generated by the invoked macro "ICODES".&lt;BR /&gt;129 select distinct enrolid, dx&amp;amp;i. as code from derived._01_itable&lt;BR /&gt;________ ____&lt;BR /&gt;78 22&lt;BR /&gt;76&lt;BR /&gt;ERROR 78-322: Expecting a ','.&lt;/P&gt;</description>
    <pubDate>Thu, 05 Jul 2018 15:07:30 GMT</pubDate>
    <dc:creator>manya92</dc:creator>
    <dc:date>2018-07-05T15:07:30Z</dc:date>
    <item>
      <title>SAS MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-MACROS/m-p/475661#M71176</link>
      <description>&lt;PRE&gt;%macro icodes ;
	
	proc sql ;
		create table _01_itable2 as
		%do i = 1 %to 14 ;
			select distinct enrolid, dx&amp;amp;i. as code 
			from derived._01_itable 
			%if i &amp;lt;14 %then %do ;
				union
			%end ;
		%end ;
		;
	quit;

%mend icodes ;
%icodes;	&lt;/PRE&gt;&lt;P&gt;Whats wrong with this code ?&lt;/P&gt;&lt;P&gt;SAS is giving me this error :-&amp;nbsp;NOTE: Line generated by the invoked macro "ICODES".&lt;BR /&gt;129 select distinct enrolid, dx&amp;amp;i. as code from derived._01_itable&lt;BR /&gt;________ ____&lt;BR /&gt;78 22&lt;BR /&gt;76&lt;BR /&gt;ERROR 78-322: Expecting a ','.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:07:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-MACROS/m-p/475661#M71176</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-07-05T15:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-MACROS/m-p/475670#M71178</link>
      <description>&lt;P&gt;Even if you get this to work, it seems extremely inefficient to read your data set 14 times just to be able to transpose the data.&amp;nbsp; Why not just use PROC TRANSPOSE?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:16:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-MACROS/m-p/475670#M71178</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-05T15:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-MACROS/m-p/475673#M71179</link>
      <description>&lt;P&gt;how to do that ? I'd like to see how to do it both by my code (macros) and proc transpose&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:18:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-MACROS/m-p/475673#M71179</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-07-05T15:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: SAS MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-MACROS/m-p/475677#M71180</link>
      <description>&lt;P&gt;Hint:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;before calling the macro, then the error message will be much easier to debug.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint 2:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When including&amp;nbsp;a SASLOG into this forum, use the {i} icon that will space the letters properly so we can see exactly what is underlined.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:19:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-MACROS/m-p/475677#M71180</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-05T15:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: SAS MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-MACROS/m-p/475680#M71181</link>
      <description>&lt;P&gt;You are comparing the letter i to the digits 14&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;i &amp;lt; 14&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead of testing the value of the macro variable i&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;i &amp;lt; 14&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-MACROS/m-p/475680#M71181</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-05T15:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: SAS MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-MACROS/m-p/475686#M71182</link>
      <description>&lt;P&gt;Just use PROC transpose&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=derived._01_itable 
  out= _01_itable2 (rename=(col1=code)) 
;
 by enrolid ;
  var dx1-dx14 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Although if you really do have multiple records per ENROLID you might need to first decide which one you want to transpose.&lt;/P&gt;
&lt;P&gt;Or create a new variable that will uniquely id the rows that you can use in the BY statement for PROC TRANSPOSE and then add a PROC SORT NODUPKEY to remove the multiple copies of the same ENROLID, CODE combinations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:27:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-MACROS/m-p/475686#M71182</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-05T15:27:04Z</dc:date>
    </item>
  </channel>
</rss>

