<?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, Datalines and a Loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-Datalines-and-a-Loop/m-p/188861#M35663</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, have to ask why?&amp;nbsp; You must have put the data into the macro variables somewhere and now your putting them back into a datastep, seems like going round in circles to me.&amp;nbsp; There are many ways to get macro variables: symget is one, you could also just use the SAS metadata tables:&lt;/P&gt;&lt;P&gt;data stats;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set sashelp.vmacro (where=(name in ("XYZ","ERT"...) keep=value);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;This returns a dataset with a list of values held in the macro variables in the in list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I return however to my original question - why?&amp;nbsp; Provide some background on the problem as 99% of the time there is no need for macro anything, just a way of thinking about the data and your process.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 27 Nov 2014 09:53:05 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2014-11-27T09:53:05Z</dc:date>
    <item>
      <title>Macro variable, Datalines and a Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-Datalines-and-a-Loop/m-p/188860#M35662</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this problem seems interesting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have:&lt;/P&gt;&lt;P&gt;- Macro Variables&lt;/P&gt;&lt;P&gt;- That I want to put in a new table (can do it easily in an existing table but i wanted to see if i can push my luck)&lt;/P&gt;&lt;P&gt;- Run a loop&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have:&lt;/P&gt;&lt;P&gt;%let rmse_1=10;&lt;/P&gt;&lt;P&gt;%let rmse_2=234.32;&lt;/P&gt;&lt;P&gt;%let rmse_3=231.24;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data stats;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input rmse $10.;/*adding it as character as it didn't work with numeric and thought i can easily convert later on*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rmse=deqoute(resolve(quote(rmse)));/*to ensure that macro variable gets read*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stop;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;&amp;amp;&amp;amp;rmse_&amp;amp;i&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Problem: I get the last rmse populated thrice in the table instead of the individual rmse. Until now unable to find a resource that uses macro variable in a datelines with a loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help is much appreciated as this will go towards building a table with lots of other stats in.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Nov 2014 09:31:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-Datalines-and-a-Loop/m-p/188860#M35662</guid>
      <dc:creator>Jane7476</dc:creator>
      <dc:date>2014-11-27T09:31:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable, Datalines and a Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-Datalines-and-a-Loop/m-p/188861#M35663</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, have to ask why?&amp;nbsp; You must have put the data into the macro variables somewhere and now your putting them back into a datastep, seems like going round in circles to me.&amp;nbsp; There are many ways to get macro variables: symget is one, you could also just use the SAS metadata tables:&lt;/P&gt;&lt;P&gt;data stats;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set sashelp.vmacro (where=(name in ("XYZ","ERT"...) keep=value);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;This returns a dataset with a list of values held in the macro variables in the in list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I return however to my original question - why?&amp;nbsp; Provide some background on the problem as 99% of the time there is no need for macro anything, just a way of thinking about the data and your process.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Nov 2014 09:53:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-Datalines-and-a-Loop/m-p/188861#M35663</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-11-27T09:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable, Datalines and a Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-Datalines-and-a-Loop/m-p/188862#M35664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As often, you confuse macro execution with data step execution; i is a data step variable, &amp;amp;i is a macro variable, both are completely disconnected.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you think you need the macro, do it this way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro datalines;&lt;/P&gt;&lt;P&gt;%do i = 1 %to 3;&lt;/P&gt;&lt;P&gt;&amp;amp;&amp;amp;rmse_&amp;amp;i&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data .....;&lt;/P&gt;&lt;P&gt;infile cards;&lt;/P&gt;&lt;P&gt;input rmse;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;%datalines&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Nov 2014 10:13:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-Datalines-and-a-Loop/m-p/188862#M35664</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2014-11-27T10:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable, Datalines and a Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-Datalines-and-a-Loop/m-p/188863#M35665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another solution:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let rmse_1=10;&lt;/P&gt;&lt;P&gt;%let rmse_2=234.32;&lt;/P&gt;&lt;P&gt;%let rmse_3=231.24;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;do i=1 to 3;&lt;/P&gt;&lt;P&gt; rmse=symget(cat("rmse_",i));&lt;/P&gt;&lt;P&gt; output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Nov 2014 10:44:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-Datalines-and-a-Loop/m-p/188863#M35665</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2014-11-27T10:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable, Datalines and a Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-Datalines-and-a-Loop/m-p/188864#M35666</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are right. Maybe there is no need for a macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The issue is: I have ods output and other tables where stats are stored. I need the stats (some from each of the tables) in a particular pre-formatted table design. Hence I thought of putting macro variables into a new table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Nov 2014 15:24:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-Datalines-and-a-Loop/m-p/188864#M35666</guid>
      <dc:creator>Jane7476</dc:creator>
      <dc:date>2014-11-28T15:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable, Datalines and a Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-Datalines-and-a-Loop/m-p/188865#M35667</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, something I do all the time.&amp;nbsp; My approach, without using any macro code:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table OUTPUT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; COL1 char(200) label "Stat",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; COL2 char(200) label "Result"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insert into OUTPUT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set COL1="n",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; COL2=(select put(n,3.) from MEANS_OUTPUT)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set COL1="mean",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; COL2=(select put(mean,5.2) from MEANS_OUTPUT)&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Think it seems a bit long winded, fine combine the approach with arrays or datasets of parameters, and call execute and you can generate a whole output table with a datastep of 5 or 6 rows, formatted etc.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Nov 2014 16:41:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-Datalines-and-a-Loop/m-p/188865#M35667</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-11-29T16:41:57Z</dc:date>
    </item>
  </channel>
</rss>

