<?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: Subset dataset using loop and macro variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565978#M158990</link>
    <description>My apologies for the abrupt reply. It was out of character. Some what of a challenging day to say the least. My response is not the way I carry myself.&lt;BR /&gt;&lt;BR /&gt;I understand you example and in most situations I would of considered the approach.&lt;BR /&gt;&lt;BR /&gt;My other post about me processing hierarchical data now has most of my code complete. However. I have it a brick wall and I just wanted to test this approach and for the life of me hit a coding block.&lt;BR /&gt;&lt;BR /&gt;Again I apologise, thank for looking at the post.</description>
    <pubDate>Thu, 13 Jun 2019 19:10:21 GMT</pubDate>
    <dc:creator>teelov</dc:creator>
    <dc:date>2019-06-13T19:10:21Z</dc:date>
    <item>
      <title>Subset dataset using loop and macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565874#M158932</link>
      <description>&lt;P&gt;good afternoon&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have a vast data-set which i want to process, the process can only be done when isolating subset of the entire data-set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;as you can see from the list below i want to be able to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;choose rows 2-6&lt;/P&gt;&lt;P&gt;rename the subset with an increment&lt;/P&gt;&lt;P&gt;run my processing %mymacro on this subset only&lt;/P&gt;&lt;P&gt;go back to the main data-set&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;choose rows 7-14&lt;/P&gt;&lt;P&gt;&amp;nbsp;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;%mymacro&lt;/P&gt;&lt;P&gt;&amp;nbsp;...&lt;/P&gt;&lt;P&gt;choose rows 15-22&lt;/P&gt;&lt;P&gt;&amp;nbsp;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;%mymacro&lt;/P&gt;&lt;P&gt;&amp;nbsp;...&lt;/P&gt;&lt;P&gt;choose rows 23-30&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and so on until the macro has processed every subset up to 199 to EOF (last _n_ is not in the list for some reason).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="startfinish.PNG" style="width: 191px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30259i6B758AA65AF56EA3/image-size/large?v=v2&amp;amp;px=999" role="button" title="startfinish.PNG" alt="startfinish.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 15:00:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565874#M158932</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2019-06-13T15:00:22Z</dc:date>
    </item>
    <item>
      <title>Re: Subset dataset using loop and macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565879#M158934</link>
      <description>It's not clear what your question is here. Which part are you having trouble with?&lt;BR /&gt;&lt;BR /&gt;For writing a macro I usually recommend you start with your working code and then macrotize it one step at a time. There's a short tutorial here. &lt;BR /&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Yours will vary for the last step because you want to choose only a few records each time. That's easy enough to do by either looping or subsetting each time. If that's the part you're having issues with, the following illustrates one method to split a data set into subsets though you could likely get away with much simpler logic.</description>
      <pubDate>Thu, 13 Jun 2019 15:04:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565879#M158934</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-13T15:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: Subset dataset using loop and macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565887#M158937</link>
      <description>&lt;P&gt;my process macro is complete&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i need to programatically create code for firstobs lastobs to create subset of the data that needs processing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so if a or macro was to go through the numbers above it would generate something like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="dataexample.PNG" style="width: 328px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30260iD1770B1F8AD74C49/image-size/large?v=v2&amp;amp;px=999" role="button" title="dataexample.PNG" alt="dataexample.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data D000100_1a;
set&amp;nbsp;D000100 (firstobs=2 obs=5);
run;

data D000100_1b;
set&amp;nbsp;D000100 (firstobs=7 obs=8);
run;

data D000100_1c;
set&amp;nbsp;D000100 (firstobs=15 obs=8);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 15:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565887#M158937</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2019-06-13T15:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Subset dataset using loop and macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565888#M158938</link>
      <description>&lt;P&gt;You would likely be way ahead in this project if you add a variable to identify the groups and then use BY group processing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example of creating output for each level of a variable using by group processing:&lt;/P&gt;
&lt;PRE&gt;proc sort data=sashelp.class out=work.class;
   by age;
run;

proc means data=work.class max min mean;
   by age;
   var height weight;
run;

proc print data=work.class;
   by age;
   var name sex;
run;&lt;/PRE&gt;
&lt;P&gt;And what happens to your "row"=1?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 15:25:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565888#M158938</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-13T15:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: Subset dataset using loop and macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565898#M158941</link>
      <description>you answer has no relevance to my question. and telling me i would be "further ahead" is slightly insulting.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Jun 2019 15:52:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565898#M158941</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2019-06-13T15:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Subset dataset using loop and macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565910#M158947</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/23443"&gt;@teelov&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;you answer has no relevance to my question. and telling me i would be "further ahead" is slightly insulting.&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I am sorry that you feel that way but your original requirement included:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;the process can only be done when isolating subset of the entire&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which is exactly what BY group processing does.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or use of the data set option WHERE with a group variable equal to the desired group (or groups).&lt;/P&gt;
&lt;P&gt;Or use of a WHERE statement in the very many procedures that support it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;None of these three approaches require creating multiple data sets, which you now have to reference explicitly and maintain.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plus by default BY group processing tells you which group is being processed, sets values that can be used to do such things as enhance Title statements, name output tabs in spreadsheets. If you want or need any of that functionality &lt;STRONG&gt;you&lt;/STRONG&gt; have to add additional coding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another issue is that if you are defining you output sets based on arbitrary observations your process is extremely fragile if you have to repeat it because you have to redefine every single start/end pair.&lt;/P&gt;
&lt;P&gt;Consider what happens if your project manager comes up and says, by the way these three records were missed previously and need to be incorporated. You will likely have to do a lot of work to get them in the correct group. If a group identifier variable was in your data set you would only have to add the group identifier for the three records, append to the data , sort for by group processing and go.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider you project manager asking to repeat the analysis but combine some arbitrary collections of records as different groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 16:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565910#M158947</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-13T16:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: Subset dataset using loop and macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565911#M158948</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/23443"&gt;@teelov&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;you answer has no relevance to my question. and telling me i would be "further ahead" is slightly insulting.&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why does it have no relevance to your question? It's a method to do iterative processing that is pretty much the standard in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want someone to code a specific answer, that's a consultants job, not the job for public user forum. The purpose of the forum is to help answer questions, but it's primarily volunteers answering the questions here who owe you absolutely nothing.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 16:20:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565911#M158948</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-13T16:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: Subset dataset using loop and macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565978#M158990</link>
      <description>My apologies for the abrupt reply. It was out of character. Some what of a challenging day to say the least. My response is not the way I carry myself.&lt;BR /&gt;&lt;BR /&gt;I understand you example and in most situations I would of considered the approach.&lt;BR /&gt;&lt;BR /&gt;My other post about me processing hierarchical data now has most of my code complete. However. I have it a brick wall and I just wanted to test this approach and for the life of me hit a coding block.&lt;BR /&gt;&lt;BR /&gt;Again I apologise, thank for looking at the post.</description>
      <pubDate>Thu, 13 Jun 2019 19:10:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-dataset-using-loop-and-macro-variables/m-p/565978#M158990</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2019-06-13T19:10:21Z</dc:date>
    </item>
  </channel>
</rss>

