<?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: Splitting the dataset using macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212374#M39226</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ok, so perhaps store-id is not a single-digit integer in sequential order with none skipped.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/List_Processing_Basics_Creating_and_Using_Lists_of_Macro_Variables" title="http://www.sascommunity.org/wiki/List_Processing_Basics_Creating_and_Using_Lists_of_Macro_Variables"&gt;http://www.sascommunity.org/wiki/List_Processing_Basics_Creating_and_Using_Lists_of_Macro_Variables&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. move the processing statements into a separate macro so you can test it&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. you're learning sql so make the list with sql select distinct store into :list_stores separated by ' ';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. the loop reads an item from the list&lt;/P&gt;&lt;P&gt;and calls the processing macro&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro do_this(store=);&lt;/P&gt;&lt;P&gt;data mypro.work&amp;amp;store;&lt;/P&gt;&lt;P&gt;set &amp;amp;dsn(where store=&amp;amp;store);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro prod(dsn);&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select distinct store into :list_stores from &amp;amp;dsn;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;sqlobs;&lt;/P&gt;&lt;P&gt;%let item = %scan(&amp;amp;list_stores,&amp;amp;i);&lt;/P&gt;&lt;P&gt;%put echo &amp;amp;=item;&lt;/P&gt;&lt;P&gt;%put do_this(store=&amp;amp;item);&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend prod;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 23 Jun 2015 21:20:54 GMT</pubDate>
    <dc:creator>Ron_MacroMaven</dc:creator>
    <dc:date>2015-06-23T21:20:54Z</dc:date>
    <item>
      <title>Splitting the dataset using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212367#M39219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;obs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; store&amp;nbsp;&amp;nbsp; product&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;&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; date&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;&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; buysell&amp;nbsp; units&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; price&lt;/P&gt;&lt;TABLE cellpadding="5" cellspacing="0" class="table" frame="box" height="262" rules="all" style="height: 264px; width: 827px;" summary="Procedure Print: Data Set MYPRO.PRODUCT" width="825"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;&lt;TD class="l data"&gt;1&lt;/TD&gt;&lt;TD class="l data"&gt;100001&lt;/TD&gt;&lt;TD class="r data"&gt;19/02/2013&lt;/TD&gt;&lt;TD class="l data"&gt;b&lt;/TD&gt;&lt;TD class="r data"&gt;1000&lt;/TD&gt;&lt;TD class="r data"&gt;$1,000.29&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;&lt;TD class="l data"&gt;1&lt;/TD&gt;&lt;TD class="l data"&gt;100001&lt;/TD&gt;&lt;TD class="r data"&gt;20/03/2013&lt;/TD&gt;&lt;TD class="l data"&gt;s&lt;/TD&gt;&lt;TD class="r data"&gt;1000&lt;/TD&gt;&lt;TD class="r data"&gt;$2,500.20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;&lt;TD class="l data"&gt;1&lt;/TD&gt;&lt;TD class="l data"&gt;100002&lt;/TD&gt;&lt;TD class="r data"&gt;17/03/2014&lt;/TD&gt;&lt;TD class="l data"&gt;b&lt;/TD&gt;&lt;TD class="r data"&gt;1000&lt;/TD&gt;&lt;TD class="r data"&gt;$2,000.20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;&lt;TD class="l data"&gt;1&lt;/TD&gt;&lt;TD class="l data"&gt;100003&lt;/TD&gt;&lt;TD class="r data"&gt;18/05/2014&lt;/TD&gt;&lt;TD class="l data"&gt;b&lt;/TD&gt;&lt;TD class="r data"&gt;2000&lt;/TD&gt;&lt;TD class="r data"&gt;$3,000.20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;&lt;TD class="l data"&gt;2&lt;/TD&gt;&lt;TD class="l data"&gt;100004&lt;/TD&gt;&lt;TD class="r data"&gt;14/05/2013&lt;/TD&gt;&lt;TD class="l data"&gt;b&lt;/TD&gt;&lt;TD class="r data"&gt;1000&lt;/TD&gt;&lt;TD class="r data"&gt;$3,000.29&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TH class="r rowheader" scope="row"&gt;6&lt;/TH&gt;&lt;TD class="l data"&gt;2&lt;/TD&gt;&lt;TD class="l data"&gt;100004&lt;/TD&gt;&lt;TD class="r data"&gt;20/06/2013&lt;/TD&gt;&lt;TD class="l data"&gt;s&lt;/TD&gt;&lt;TD class="r data"&gt;1000&lt;/TD&gt;&lt;TD class="r data"&gt;$3,500.20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TH class="r rowheader" scope="row"&gt;7&lt;/TH&gt;&lt;TD class="l data"&gt;2&lt;/TD&gt;&lt;TD class="l data"&gt;100005&lt;/TD&gt;&lt;TD class="r data"&gt;17/03/2014&lt;/TD&gt;&lt;TD class="l data"&gt;b&lt;/TD&gt;&lt;TD class="r data"&gt;1000&lt;/TD&gt;&lt;TD class="r data"&gt;$2,000.20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TH class="r rowheader" scope="row"&gt;8&lt;/TH&gt;&lt;TD class="l data"&gt;2&lt;/TD&gt;&lt;TD class="l data"&gt;100006&lt;/TD&gt;&lt;TD class="r data"&gt;18/05/2014&lt;/TD&gt;&lt;TD class="l data"&gt;b&lt;/TD&gt;&lt;TD class="r data"&gt;2000&lt;/TD&gt;&lt;TD class="r data"&gt;$3,000.20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TH class="r rowheader" scope="row"&gt;9&lt;/TH&gt;&lt;TD class="l data"&gt;2&lt;/TD&gt;&lt;TD class="l data"&gt;100007&lt;/TD&gt;&lt;TD class="r data"&gt;20/09/2013&lt;/TD&gt;&lt;TD class="l data"&gt;s&lt;/TD&gt;&lt;TD class="r data"&gt;1000&lt;/TD&gt;&lt;TD class="r data"&gt;$3,500.20&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;how can I split this data set into different number of datasets according to the store and name that datasets as work_i where i is the number of store?&lt;/P&gt;&lt;P&gt;This is my coding &lt;/P&gt;&lt;P&gt;%macro prod(dsn);&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select distinct max(store) into:x from &amp;amp;dsn;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;x;&lt;/P&gt;&lt;P&gt;data mypro.work&amp;amp;i;&lt;/P&gt;&lt;P&gt;set &amp;amp;dsn;&lt;/P&gt;&lt;P&gt;%where store='i';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend prod;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jun 2015 18:07:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212367#M39219</guid>
      <dc:creator>johnsaini</dc:creator>
      <dc:date>2015-06-23T18:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the dataset using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212368#M39220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Seems like a learning exercise.&amp;nbsp; As a first step, I would suggest try writing two DATA steps that you would use to make mypro.Work1 and mypro.Work2.&amp;nbsp;&amp;nbsp; Then once you have those DATA steps, try updating the macro to generate those two steps.&amp;nbsp; Remember, the macro language is mostly just a SAS code generator, so when learning macro language, it sometimes helps to type the SAS code yourself, and get it working, before using the macro language to generate code.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jun 2015 18:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212368#M39220</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2015-06-23T18:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the dataset using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212369#M39221</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1. Don't do this. use by-processing instead&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. YeahBut for the learning --- making mistakes --- experience&lt;/P&gt;&lt;P&gt;read up on the history of the problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/Category:Making_subsets" title="http://www.sascommunity.org/wiki/Category:Making_subsets"&gt;Category:Making subsets - sasCommunity&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jun 2015 18:39:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212369#M39221</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2015-06-23T18:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the dataset using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212370#M39222</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would do some research into the call symputx macro function combined with the cats function on the auto SAS variable _N_.&amp;nbsp; This will loop through a data set with the values equal to a specific variable (in this case store is what you'd want).&amp;nbsp; I provided some code below, assuming that the store variable is numeric.&amp;nbsp; If it's character then there needs to be double quotations around the &amp;amp;&amp;amp;store&amp;amp;i=&amp;gt;"&amp;amp;&amp;amp;store&amp;amp;i".&amp;nbsp; I would recommend researching and trying to get an understanding of what the code is actually doing so you can manipulate and modify it moving forward as you continue programming.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;input store product date buysell $ units price;&lt;/P&gt;&lt;P&gt;informat date ddmmyy10. price dollar20.2;&lt;/P&gt;&lt;P&gt;format date ddmmyy10. price dollar20.2;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 100001 19/02/2013 b 1000 $1,000.29&lt;/P&gt;&lt;P&gt;1 100001 20/03/2013 s 1000 $2,500.20&lt;/P&gt;&lt;P&gt;1 100002 17/03/2014 b 1000 $2,000.20&lt;/P&gt;&lt;P&gt;1 100003 18/05/2014 b 2000 $3,000.20&lt;/P&gt;&lt;P&gt;2 100004 14/05/2013 b 1000 $3,000.29&lt;/P&gt;&lt;P&gt;2 100004 20/06/2013 s 1000 $3,500.20&lt;/P&gt;&lt;P&gt;2 100005 17/03/2014 b 1000 $2,000.20&lt;/P&gt;&lt;P&gt;2 100006 18/05/2014 b 2000 $3,000.20&lt;/P&gt;&lt;P&gt;2 100007 20/09/2013 s 1000 $3,500.20&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;/***** REMOVE DUPLICATE RECORDS OF STORE *****/&lt;/P&gt;&lt;P&gt;proc sort data=test nodupkey&lt;/P&gt;&lt;P&gt;out=test_unique_store;&lt;/P&gt;&lt;P&gt;by store;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro prod(dsn);&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set test_unique_store end=last; /***** USE UNIQUE STORE DATA SET *****/&lt;/P&gt;&lt;P&gt;call symputx(cats("store",_n_),store);&lt;/P&gt;&lt;P&gt;If last then call symputx("n",_n_);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;n; /***** &amp;amp;N IS THE VALUE OF THE NUMBER OF UNIQUE STORES (IN THIS EXAMPLE 1 AND 2) *****/&lt;/P&gt;&lt;P&gt;data mypro.work&amp;amp;i;&lt;/P&gt;&lt;P&gt;set &amp;amp;dsn;&lt;/P&gt;&lt;P&gt;where store=&amp;amp;&amp;amp;store&amp;amp;i;&lt;/P&gt;&lt;P&gt;run; %end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%prod(test)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jun 2015 18:39:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212370#M39222</guid>
      <dc:creator>dcruik</dc:creator>
      <dc:date>2015-06-23T18:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the dataset using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212371#M39223</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;in this case we know that the maximum value of stores are 2, but how about if the value of store is a large number, then?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jun 2015 20:19:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212371#M39223</guid>
      <dc:creator>johnsaini</dc:creator>
      <dc:date>2015-06-23T20:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the dataset using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212372#M39224</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Your original code is almost good (if store numbers are 1.. N consecutive integers).&lt;/P&gt;&lt;P&gt;Change this:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;%where store='i';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;to:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;where store="&amp;amp;i"; /*if store is a string*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;or:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;where store=&amp;amp;i;&amp;nbsp; /*if store is a number*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;You don't need the distinct keyword in the select statement (but it does not hurt in this case).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;And I agree with previous posts: don't do it, unless you have a very good reason for it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;Why do you want to do this? Maybe we can offer a better solution then splitting the data set.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jun 2015 20:57:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212372#M39224</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2015-06-23T20:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the dataset using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212373#M39225</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much its working now&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jun 2015 21:12:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212373#M39225</guid>
      <dc:creator>johnsaini</dc:creator>
      <dc:date>2015-06-23T21:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the dataset using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212374#M39226</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ok, so perhaps store-id is not a single-digit integer in sequential order with none skipped.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/List_Processing_Basics_Creating_and_Using_Lists_of_Macro_Variables" title="http://www.sascommunity.org/wiki/List_Processing_Basics_Creating_and_Using_Lists_of_Macro_Variables"&gt;http://www.sascommunity.org/wiki/List_Processing_Basics_Creating_and_Using_Lists_of_Macro_Variables&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. move the processing statements into a separate macro so you can test it&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. you're learning sql so make the list with sql select distinct store into :list_stores separated by ' ';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. the loop reads an item from the list&lt;/P&gt;&lt;P&gt;and calls the processing macro&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro do_this(store=);&lt;/P&gt;&lt;P&gt;data mypro.work&amp;amp;store;&lt;/P&gt;&lt;P&gt;set &amp;amp;dsn(where store=&amp;amp;store);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro prod(dsn);&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select distinct store into :list_stores from &amp;amp;dsn;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;sqlobs;&lt;/P&gt;&lt;P&gt;%let item = %scan(&amp;amp;list_stores,&amp;amp;i);&lt;/P&gt;&lt;P&gt;%put echo &amp;amp;=item;&lt;/P&gt;&lt;P&gt;%put do_this(store=&amp;amp;item);&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend prod;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jun 2015 21:20:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212374#M39226</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2015-06-23T21:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the dataset using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212375#M39227</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can put *all* the store IDs in a macro variable, then %SCAN that list, pulling the ID's off one-at-a-time:&lt;/P&gt;&lt;P&gt;(This assumes the IDs are all integers)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;attrib&amp;nbsp; date informat=ddmmyy10. format=date9.&lt;BR /&gt;&amp;nbsp; buysell informat=$1.&lt;BR /&gt;&amp;nbsp; price informat=dollar9.2 format=dollar9.2&lt;BR /&gt;;&lt;BR /&gt;input&amp;nbsp; store product date&amp;nbsp;&amp;nbsp; buysell&amp;nbsp;&amp;nbsp; units price&amp;nbsp;&amp;nbsp; ;&lt;BR /&gt; cards;&lt;BR /&gt; 1 100001 19/02/2013 b 1000 $1,000.29 &lt;BR /&gt; 1 100001 20/03/2013 s 1000 $2,500.20 &lt;BR /&gt; 1 100002 17/03/2014 b 1000 $2,000.20 &lt;BR /&gt; 1 100003 18/05/2014 b 2000 $3,000.20 &lt;BR /&gt; 2 100004 14/05/2013 b 1000 $3,000.29 &lt;BR /&gt; 2 100004 20/06/2013 s 1000 $3,500.20 &lt;BR /&gt; 2 100005 17/03/2014 b 1000 $2,000.20 &lt;BR /&gt; 2 100006 18/05/2014 b 2000 $3,000.20 &lt;BR /&gt; 2 100007 20/09/2013 s 1000 $3,500.20 &lt;BR /&gt; 9 123456 01/01/2001 b 9999 $1,234.56&lt;BR /&gt; 39 33333 03/03/2003 x 3333 $3,333.33&lt;BR /&gt;run;&lt;BR /&gt; proc print; run;&lt;/P&gt;&lt;P&gt; options mprint mlogic symbolgen ;&lt;BR /&gt;%macro prod2(dsn);&lt;BR /&gt;proc sql;&lt;BR /&gt;select distinct store into :xall separated by ' ' from &amp;amp;dsn;&lt;BR /&gt;quit;&lt;BR /&gt;%put&amp;nbsp;&amp;nbsp; &amp;amp;xall= ;&lt;/P&gt;&lt;P&gt;%let I = 1;&lt;BR /&gt;%do %while (%scan(&amp;amp;xall,&amp;amp;i) ne );&lt;BR /&gt; %let ID = %scan(&amp;amp;xall,&amp;amp;i); %put &amp;amp;ID= ;&lt;BR /&gt;data work.work_&amp;amp;id;&lt;BR /&gt;set &amp;amp;dsn(where=(store=%eval(&amp;amp;id)));&lt;BR /&gt;run;&lt;BR /&gt;%let I = %eval(&amp;amp;I + 1);&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%mend prod2;&lt;/P&gt;&lt;P&gt;%prod2(work.one)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jun 2015 21:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212375#M39227</guid>
      <dc:creator>Tommywhosc</dc:creator>
      <dc:date>2015-06-23T21:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the dataset using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212376#M39228</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;Hi John,&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;You can try the below code also.&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;Let us assume the input dataset as "storeData"&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;%Maco splittingDatasets(dsn=);&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;proc sql;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;select count(distinct store) into :storeCnt from &amp;amp;dsn;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;%let storeCount = %cmpres(&amp;amp;storeCnt);&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;select distinct store into :store1 - :store&amp;amp;storeCount from &amp;amp;dsn;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;quit;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;%do i = 1 %to &amp;amp;storeCount;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;data store&amp;amp;i;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;set &amp;amp;dsn;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;where store = &amp;amp;&amp;amp;store&amp;amp;i;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;run;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;%end;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;%mend;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;%splittingDatasets(dsn = storeData )&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jun 2015 11:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212376#M39228</guid>
      <dc:creator>MadhuKorni</dc:creator>
      <dc:date>2015-06-24T11:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the dataset using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212377#M39229</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, I see this approach a lot.&amp;nbsp; I personally don't like the macro language involved with macro variable lists, and there are limitations to the length.&amp;nbsp; You can modify your code slightly to get the same effect without the limitations and macro code however:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table LOOP as select distinct STORE from DATASET;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set loop;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute('data want'||strip(store)||'; set have (where=(store="'||strip(store)||'")); run;');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jun 2015 12:23:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212377#M39229</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-06-24T12:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the dataset using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212378#M39230</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One more comment ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should realize that even if you succeed at this task, you are accomplishing it in an inefficient way.&amp;nbsp; This code takes longer to run:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data store1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set &amp;amp;dsn;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; where store='1';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data store2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set &amp;amp;dsn;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; where store='2';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code would run faster:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data store1 store2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set &amp;amp;dsn;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if store='1' then output store1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else if store='2' then output store2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Macro language could generate the faster-running program, as well as the slower-running program.&amp;nbsp; It's perhaps a bit more complex to generate the faster-running program, so if this is really just a learning exercise it may be too much too soon.&amp;nbsp; And if your data sets are small, speed would be a secondary consideration anyway.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jun 2015 13:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212378#M39230</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-06-24T13:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the dataset using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212379#M39231</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just to add another non-macro alternative (not that I think the macro language is a bad choice for this problem), I'm amazed by the magic of what can be done with the hash object.&amp;nbsp; Below hash-splitting is based on example from a Paul Dorfman paper, &lt;A class="active_link" href="http://www.lexjansen.com/nesug/nesug09/hw/HW04.pdf"&gt;http://www.lexjansen.com/nesug/nesug09/hw/HW04.pdf&lt;/A&gt;&lt;/P&gt;&lt;PRE&gt;219&amp;nbsp; *data _null_ step that outputs multiple datatsets ;
220&amp;nbsp; data _null_&amp;nbsp; ;
221&amp;nbsp;&amp;nbsp;&amp;nbsp; if _n_=1 then do ;
222&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash h() ;
223&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definekey ("_n_") ;
224&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definedata ("store","product","date","buysell","units","price") ;
225&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definedone () ;
226&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
227&amp;nbsp;&amp;nbsp;&amp;nbsp; do _n_ = 1 by 1 until (last.store) ;
228&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have ;
229&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by store ;
230&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.add() ;
231&amp;nbsp;&amp;nbsp;&amp;nbsp; end ;
232&amp;nbsp;&amp;nbsp;&amp;nbsp; h.output (dataset: cats("Store_",store) ) ;
233&amp;nbsp;&amp;nbsp;&amp;nbsp; h.clear() ;
234&amp;nbsp; run ;

NOTE: The data set WORK.STORE_1 has 4 observations and 6 variables.
NOTE: The data set WORK.STORE_2 has 5 observations and 6 variables.
NOTE: There were 9 observations read from the data set WORK.HAVE.

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jun 2015 14:33:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-dataset-using-macros/m-p/212379#M39231</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2015-06-24T14:33:43Z</dc:date>
    </item>
  </channel>
</rss>

