<?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 why statement &amp;quot;fcod=&amp;i&amp;quot; in macro does not work? How to use &amp;quot;rename&amp;quot; statements in Macro? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/why-statement-quot-fcod-i-quot-in-macro-does-not-work-How-to-use/m-p/116715#M24102</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wan to split a data set&amp;nbsp; with variables lpt1 -lpt9 and&amp;nbsp; generate a new varialbe in new data sets. Run the following code &lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;%do i=1 %to 9;&lt;/P&gt;&lt;P&gt;data test&amp;amp;i;&lt;/P&gt;&lt;P&gt;keep lpd&amp;amp;i;&lt;/P&gt;&lt;P&gt;fcod=&amp;amp;i;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%test;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is&amp;nbsp; no variable fcod in new data set. why?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another question:&lt;/P&gt;&lt;P&gt;I wand to rename variables in data set test1-test9 and run the following code ;&lt;/P&gt;&lt;P&gt;%macro rename;&lt;/P&gt;&lt;P&gt;%do i=1 %to 9;&lt;/P&gt;&lt;P&gt;data test&amp;amp;i;&lt;/P&gt;&lt;P&gt;set test&amp;amp;i;&lt;/P&gt;&lt;P&gt;rename LPT&amp;amp;i=lpt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%rename;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS gives the following error message&lt;/P&gt;&lt;P&gt;"WARNING: The variable lpt1 in the DROP, KEEP, or RENAME list has never been referenced"&lt;/P&gt;&lt;P&gt;Whate's the mistake i made?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 24 Jun 2013 06:59:42 GMT</pubDate>
    <dc:creator>ShufeGuoding</dc:creator>
    <dc:date>2013-06-24T06:59:42Z</dc:date>
    <item>
      <title>why statement "fcod=&amp;i" in macro does not work? How to use "rename" statements in Macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-statement-quot-fcod-i-quot-in-macro-does-not-work-How-to-use/m-p/116715#M24102</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wan to split a data set&amp;nbsp; with variables lpt1 -lpt9 and&amp;nbsp; generate a new varialbe in new data sets. Run the following code &lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;%do i=1 %to 9;&lt;/P&gt;&lt;P&gt;data test&amp;amp;i;&lt;/P&gt;&lt;P&gt;keep lpd&amp;amp;i;&lt;/P&gt;&lt;P&gt;fcod=&amp;amp;i;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%test;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is&amp;nbsp; no variable fcod in new data set. why?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another question:&lt;/P&gt;&lt;P&gt;I wand to rename variables in data set test1-test9 and run the following code ;&lt;/P&gt;&lt;P&gt;%macro rename;&lt;/P&gt;&lt;P&gt;%do i=1 %to 9;&lt;/P&gt;&lt;P&gt;data test&amp;amp;i;&lt;/P&gt;&lt;P&gt;set test&amp;amp;i;&lt;/P&gt;&lt;P&gt;rename LPT&amp;amp;i=lpt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%rename;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS gives the following error message&lt;/P&gt;&lt;P&gt;"WARNING: The variable lpt1 in the DROP, KEEP, or RENAME list has never been referenced"&lt;/P&gt;&lt;P&gt;Whate's the mistake i made?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Jun 2013 06:59:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-statement-quot-fcod-i-quot-in-macro-does-not-work-How-to-use/m-p/116715#M24102</guid>
      <dc:creator>ShufeGuoding</dc:creator>
      <dc:date>2013-06-24T06:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: why statement "fcod=&amp;i" in macro does not work? How to use "rename" statements in Macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-statement-quot-fcod-i-quot-in-macro-does-not-work-How-to-use/m-p/116716#M24103</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you have not mentioned SET Statement and used KEEP Statement...So SAS is giving you error like variables in KEEP statement has never been refrenced...and u can also rename the variables in the same %DO Loops...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;%macro loop;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; %do i = 1 %to 9;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data test&amp;amp;i.(keep = lpt fcod);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set SPECIFY_DATASET_NAME(keep = lpt&amp;amp;i.); /* you missed it */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fcod = &amp;amp;i.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rename lpt&amp;amp;i. = lpt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; %end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;%loop;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;-Urvish&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Jun 2013 07:27:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-statement-quot-fcod-i-quot-in-macro-does-not-work-How-to-use/m-p/116716#M24103</guid>
      <dc:creator>UrvishShah</dc:creator>
      <dc:date>2013-06-24T07:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: why statement "fcod=&amp;i" in macro does not work? How to use "rename" statements in Macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-statement-quot-fcod-i-quot-in-macro-does-not-work-How-to-use/m-p/116717#M24104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you really do not have an existing SAS data set that should have been used in a &lt;SPAN style="font-family: 'courier new', courier;"&gt;set&lt;/SPAN&gt; statement as Urvish suggested, then try changing the &lt;SPAN style="font-family: 'courier new', courier;"&gt;keep&lt;/SPAN&gt; statement to a &lt;SPAN style="font-family: 'courier new', courier;"&gt;length&lt;/SPAN&gt; statement, e.g.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %do i=1 %to 9;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data test&amp;amp;i;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length lpd&amp;amp;i $ 8; /* remove the "$" if numeric */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fcod=&amp;amp;i;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your next data step you want to rename &lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;LPT&amp;amp;i &lt;/SPAN&gt;variables, but you named them &lt;SPAN style="font-family: 'courier new', courier;"&gt;lpd&amp;amp;i&lt;/SPAN&gt; in your first data step, they should both be the same if you meant to refer to the same variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Further, if you want to just rename them later to remove the value generated by the macro variable &lt;SPAN style="font-family: 'courier new', courier;"&gt;i&lt;/SPAN&gt;, then you could just create the variable in your first data step without the macro variable,&amp;nbsp; which will remove the need for the second data step. E.g. you could use the following in your first data step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;length lpd $ 8; /* remove the "$" if numeric */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Jun 2013 12:17:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-statement-quot-fcod-i-quot-in-macro-does-not-work-How-to-use/m-p/116717#M24104</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2013-06-24T12:17:45Z</dc:date>
    </item>
  </channel>
</rss>

