<?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: execute each value of macro variable once for the set of steps and append to a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/execute-each-value-of-macro-variable-once-for-the-set-of-steps/m-p/478807#M123500</link>
    <description>&lt;P&gt;Define what "top 10" means.&lt;/P&gt;
&lt;P&gt;You should consider having an actual date value instead of text month so that anything that ever wants order by time actually has a chance of working. Graphs are a good example unless you really like having April next to August at the start of a graph...&lt;/P&gt;
&lt;P&gt;With an actual date value you could have multiple years worth of data in a&amp;nbsp; single data set and select records by time as needed.&lt;/P&gt;</description>
    <pubDate>Tue, 17 Jul 2018 20:06:09 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-07-17T20:06:09Z</dc:date>
    <item>
      <title>execute each value of macro variable once for the set of steps and append to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-each-value-of-macro-variable-once-for-the-set-of-steps/m-p/478785#M123491</link>
      <description>&lt;P&gt;I am trying to execute each value of my macro variable once for the set of steps(bunch of proc sql and data steps) and append the results to a sas data set.&lt;/P&gt;&lt;P&gt;Suppose I have the code like this&lt;/P&gt;&lt;P&gt;*macro variable&lt;/P&gt;&lt;P&gt;%let Customer_ID=(‘N10045’)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc sql;&lt;/P&gt;&lt;P&gt;….&lt;/P&gt;&lt;P&gt;Where customer_id =&amp;amp;Customer_ID&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;Proc sql;&lt;/P&gt;&lt;P&gt;…..&lt;/P&gt;&lt;P&gt;Data;&lt;/P&gt;&lt;P&gt;…..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Final data set &amp;nbsp;has three columns Customer_ID,MONTH, Value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works fine but now what I want is suppose to find the top 10 customer_id which is coming from table table1&lt;/P&gt;&lt;P&gt;Select top 10 customer_id from table1;&lt;/P&gt;&lt;P&gt;So what I am looking for is, it has to consider the first customer_id and form a data set Customer_ID,MONTH, Value . So the next customer_id should be appended to the dataset.&lt;/P&gt;&lt;P&gt;Which might look like this table&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;customer_id&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;MONTH&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;value&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;N1205&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;jan&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;678&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;N1205&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;feb&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2869&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;N1205&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;march&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2676&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;N1205&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;august&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;278&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;N17890&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;jan&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;6898&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;N17890&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;march&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2178&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;N17890&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Jun&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2188&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My steps does not want all to be bought at the same time for execution as it messes up the data as I have to created bunch of macros. How do I bring in each value of customer_id from table1 and find the final_data_set and append to final_data_set?&lt;/P&gt;&lt;P&gt;sas EG version 7.12&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 19:22:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-each-value-of-macro-variable-once-for-the-set-of-steps/m-p/478785#M123491</guid>
      <dc:creator>Vk_2</dc:creator>
      <dc:date>2018-07-17T19:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: execute each value of macro variable once for the set of steps and append to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-each-value-of-macro-variable-once-for-the-set-of-steps/m-p/478790#M123492</link>
      <description>&lt;P&gt;Add the PROC APPEND step to the end, but look into CALL EXECUTE to call it rather than have a macro variable list.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may also be easier to do BY group processing depending on what you're doing, but we can't tell that from what you've posted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A more complex example is here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/b308ac2cfc9b4db0ee3d793567627af0" target="_blank"&gt;https://gist.github.com/statgeek/b308ac2cfc9b4db0ee3d793567627af0&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 19:28:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-each-value-of-macro-variable-once-for-the-set-of-steps/m-p/478790#M123492</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-17T19:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: execute each value of macro variable once for the set of steps and append to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-each-value-of-macro-variable-once-for-the-set-of-steps/m-p/478807#M123500</link>
      <description>&lt;P&gt;Define what "top 10" means.&lt;/P&gt;
&lt;P&gt;You should consider having an actual date value instead of text month so that anything that ever wants order by time actually has a chance of working. Graphs are a good example unless you really like having April next to August at the start of a graph...&lt;/P&gt;
&lt;P&gt;With an actual date value you could have multiple years worth of data in a&amp;nbsp; single data set and select records by time as needed.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 20:06:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-each-value-of-macro-variable-once-for-the-set-of-steps/m-p/478807#M123500</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-17T20:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: execute each value of macro variable once for the set of steps and append to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-each-value-of-macro-variable-once-for-the-set-of-steps/m-p/478823#M123509</link>
      <description>&lt;P&gt;Top 10 is for a specific year -Select top 10 customer_id from table1 where year=’2016’&lt;/P&gt;&lt;P&gt;That was just an example to be precise my months have number value which is months of exposure. I have continuous values for months for each customer_id. The reason why I am not bringing all the customer_id ‘s at once is I have product codes which they buy commonly for each customer which I am saving as a macro variable. Which is the reason I wanted to consider one customer id at a time. This may not be the most efficient. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 20:43:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-each-value-of-macro-variable-once-for-the-set-of-steps/m-p/478823#M123509</guid>
      <dc:creator>Vk_2</dc:creator>
      <dc:date>2018-07-17T20:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: execute each value of macro variable once for the set of steps and append to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-each-value-of-macro-variable-once-for-the-set-of-steps/m-p/478841#M123513</link>
      <description>&lt;P&gt;You are making it hard for yourself by structuring your data with separate MONTH and YEAR variables. You will find it is much easier if you create a SAS DATE variable which combines your MONTH and YEAR variables.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 21:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-each-value-of-macro-variable-once-for-the-set-of-steps/m-p/478841#M123513</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-07-17T21:24:25Z</dc:date>
    </item>
  </channel>
</rss>

