<?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 issue in subset dataset with macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/issue-in-subset-dataset-with-macro/m-p/298229#M62700</link>
    <description>Hi, Can anyone please help me on below scenario. battrid test HEMA HB HEMA WBC CHEM SGPT CHEM SGOT I have this dataset where i have distinct groups. I want to create new datasets according to distinct groups. For Example, if group is HEMA then new dataset should be HEMA having correspoding records only and if group name is CHEM then new datset name should be CHEM with corresponding records. I have programmed a code , but that is not working as expected. Rajesh.</description>
    <pubDate>Wed, 14 Sep 2016 07:05:41 GMT</pubDate>
    <dc:creator>draroda</dc:creator>
    <dc:date>2016-09-14T07:05:41Z</dc:date>
    <item>
      <title>issue in subset dataset with macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issue-in-subset-dataset-with-macro/m-p/298229#M62700</link>
      <description>Hi, Can anyone please help me on below scenario. battrid test HEMA HB HEMA WBC CHEM SGPT CHEM SGOT I have this dataset where i have distinct groups. I want to create new datasets according to distinct groups. For Example, if group is HEMA then new dataset should be HEMA having correspoding records only and if group name is CHEM then new datset name should be CHEM with corresponding records. I have programmed a code , but that is not working as expected. Rajesh.</description>
      <pubDate>Wed, 14 Sep 2016 07:05:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issue-in-subset-dataset-with-macro/m-p/298229#M62700</guid>
      <dc:creator>draroda</dc:creator>
      <dc:date>2016-09-14T07:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: issue in subset dataset with macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issue-in-subset-dataset-with-macro/m-p/298233#M62701</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct(battrid) into :groups separated by " " from lbload;
quit;

data _null_;
groups = "&amp;amp;groups";
call execute("data ");
do i = 1 to countw(groups);
  call execute(scan(groups,i)!!" ");
end;
call execute("; set lbload; select(battrid);");
do i = 1 to countw(groups);
  call execute('when("'!!scan(groups,i)!!'") output '!!scan(groups,i)!!';');
end;
call execute('end; run;');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is of course completely untested and depends on the number of distinct battrid's to work; with high cardinality, you might run into memory problems. If you only have 8, that should work like a charm.&lt;/P&gt;
&lt;P&gt;Another method would be to use call execute to create a single data step for each group, but that would multiply the scans through lbload, therefore be less performant.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: added "end" in final call execute&lt;/P&gt;
&lt;P&gt;Worked fine with test data from&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lbload;
input battrid $ value;
cards;
HEMA 1
HB 1
HEMA 2
WBC 1
CHEM 1
SGPT 1
CHEM 2
SGOT 1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Sep 2016 07:38:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issue-in-subset-dataset-with-macro/m-p/298233#M62701</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-14T07:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: issue in subset dataset with macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/issue-in-subset-dataset-with-macro/m-p/298250#M62705</link>
      <description>&lt;P&gt;Why do you not use an industry standard data structure such as CDISC LAB, LB, ADLB models? &amp;nbsp;You will find your programming much easier to use normalised data (i.e. test - result per row, rather than in columns) as you can then use by group processing - i.e. no need to create separate files, know what columns are called etc.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.cdisc.org/standards/foundational/lab" target="_blank"&gt;https://www.cdisc.org/standards/foundational/lab&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;For example, to print your multiple datasets you would need a step for each datastep, for me using normalised data and by groups:&lt;/P&gt;
&lt;PRE&gt;proc print data=have; 
  by parcat;
  title "Category=#byval1";
run;&lt;/PRE&gt;
&lt;P&gt;Will produce print output of the data separated by the parameter categories, far easier to maintain.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 08:44:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/issue-in-subset-dataset-with-macro/m-p/298250#M62705</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-09-14T08:44:19Z</dc:date>
    </item>
  </channel>
</rss>

