<?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: variable name corresponding to macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/variable-name-corresponding-to-macro-variable/m-p/25680#M4487</link>
    <description>You are close.  try the following untested code in sas9.2 or earlier:&lt;BR /&gt;
[pre]%macro cecodes;&lt;BR /&gt;
data vir; &lt;BR /&gt;
set &lt;BR /&gt;
%do i=1 %to &amp;amp;nobs.;&lt;BR /&gt;
ref.&amp;amp;&amp;amp;var&amp;amp;i(in=in&amp;amp;&amp;amp;var&amp;amp;i)&lt;BR /&gt;
%end;;&lt;BR /&gt;
 &lt;BR /&gt;
%do i=1 %to &amp;amp;nobs.;&lt;BR /&gt;
%if &amp;amp;i gt 1 %then else;&lt;BR /&gt;
if in&amp;amp;&amp;amp;var&amp;amp;i then cecode="&amp;amp;&amp;amp;var&amp;amp;i";&lt;BR /&gt;
%end;&lt;BR /&gt;
run;&lt;BR /&gt;
%mend cecodes;&lt;BR /&gt;
%cecodes  [/pre]&lt;BR /&gt;
&lt;BR /&gt;
A second %DO builds the if-then/else.  Notice the double quotes around the constant value for CECODE.</description>
    <pubDate>Fri, 29 Oct 2010 21:03:37 GMT</pubDate>
    <dc:creator>ArtC</dc:creator>
    <dc:date>2010-10-29T21:03:37Z</dc:date>
    <item>
      <title>variable name corresponding to macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/variable-name-corresponding-to-macro-variable/m-p/25679#M4486</link>
      <description>How to print the cecode that corresponds to &amp;amp;&amp;amp;var&amp;amp;i?&lt;BR /&gt;
What happens is that i is taking the next value instead of the current value.&lt;BR /&gt;
say &amp;amp;&amp;amp;var&amp;amp;i for i=1 resolves to 'AMPS' and for i=2 resolves to 'ACOP'. i want to print cecode as 'AMPS' when it reads values from AMPS dataset ,ACOP when it reads values from ACOP dataset in ref library.The records are appended in the set statement and a final dataset vir is created.&lt;BR /&gt;
&lt;BR /&gt;
%macro cecodes;&lt;BR /&gt;
data vir; &lt;BR /&gt;
 set  &lt;BR /&gt;
     %do i=1 %to &amp;amp;nobs.;&lt;BR /&gt;
	      ref.&amp;amp;&amp;amp;var&amp;amp;i&lt;BR /&gt;
         %end;;&lt;BR /&gt;
     cecode=&amp;amp;&amp;amp;var&amp;amp;i;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
%mend cecodes;&lt;BR /&gt;
%cecodes;</description>
      <pubDate>Fri, 29 Oct 2010 19:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/variable-name-corresponding-to-macro-variable/m-p/25679#M4486</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2010-10-29T19:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: variable name corresponding to macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/variable-name-corresponding-to-macro-variable/m-p/25680#M4487</link>
      <description>You are close.  try the following untested code in sas9.2 or earlier:&lt;BR /&gt;
[pre]%macro cecodes;&lt;BR /&gt;
data vir; &lt;BR /&gt;
set &lt;BR /&gt;
%do i=1 %to &amp;amp;nobs.;&lt;BR /&gt;
ref.&amp;amp;&amp;amp;var&amp;amp;i(in=in&amp;amp;&amp;amp;var&amp;amp;i)&lt;BR /&gt;
%end;;&lt;BR /&gt;
 &lt;BR /&gt;
%do i=1 %to &amp;amp;nobs.;&lt;BR /&gt;
%if &amp;amp;i gt 1 %then else;&lt;BR /&gt;
if in&amp;amp;&amp;amp;var&amp;amp;i then cecode="&amp;amp;&amp;amp;var&amp;amp;i";&lt;BR /&gt;
%end;&lt;BR /&gt;
run;&lt;BR /&gt;
%mend cecodes;&lt;BR /&gt;
%cecodes  [/pre]&lt;BR /&gt;
&lt;BR /&gt;
A second %DO builds the if-then/else.  Notice the double quotes around the constant value for CECODE.</description>
      <pubDate>Fri, 29 Oct 2010 21:03:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/variable-name-corresponding-to-macro-variable/m-p/25680#M4487</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-10-29T21:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: variable name corresponding to macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/variable-name-corresponding-to-macro-variable/m-p/25681#M4488</link>
      <description>Where is &amp;amp;nobs assigned - also, is it intentional that you have reference to &amp;amp;i outside your %DO loop?  Lastly, suggest adding this code to help SAS generate the most diagnostics output for your desk-checking with SAS compilation:&lt;BR /&gt;
&lt;BR /&gt;
OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MPRINT /* MLOGIC */;&lt;BR /&gt;
&lt;BR /&gt;
And, with the above code added, suggest the OP re-post a reply with the SAS-generated log output revealed, not just the code-piece -- presuming the problem is still not solved with additional log diagnostics info.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sat, 30 Oct 2010 15:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/variable-name-corresponding-to-macro-variable/m-p/25681#M4488</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-10-30T15:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: variable name corresponding to macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/variable-name-corresponding-to-macro-variable/m-p/25682#M4489</link>
      <description>PROC SQL;&lt;BR /&gt;
select codes into:var1-:var20 from cecodes;&lt;BR /&gt;
select count(*) into:nobs from cecodes;&lt;BR /&gt;
QUIT;&lt;BR /&gt;
%put &amp;amp;nobs;</description>
      <pubDate>Sat, 30 Oct 2010 23:28:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/variable-name-corresponding-to-macro-variable/m-p/25682#M4489</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2010-10-30T23:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: variable name corresponding to macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/variable-name-corresponding-to-macro-variable/m-p/25683#M4490</link>
      <description>And, so, take this opportunity to debug your SAS program, as suggested, with the additional OPTIONS statement no less.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sun, 31 Oct 2010 02:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/variable-name-corresponding-to-macro-variable/m-p/25683#M4490</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-10-31T02:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: variable name corresponding to macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/variable-name-corresponding-to-macro-variable/m-p/25684#M4491</link>
      <description>I will look into it.Thanks.</description>
      <pubDate>Mon, 01 Nov 2010 01:58:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/variable-name-corresponding-to-macro-variable/m-p/25684#M4491</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2010-11-01T01:58:54Z</dc:date>
    </item>
  </channel>
</rss>

