<?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: Based on value dataset creation ..using macros. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567155#M11452</link>
    <description>&lt;P&gt;DATASET EMPloyee having :&lt;BR /&gt;Name Age Department&lt;BR /&gt;John 39 Sales&lt;BR /&gt;Mary 29 Marketing&lt;BR /&gt;Sam 32 HR&lt;BR /&gt;Rob 61 Sales&lt;BR /&gt;Toni 23 Marketing&lt;BR /&gt;Georg 39 HR&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The desired output should be&lt;/P&gt;&lt;P&gt;Data set should be created under name "sales"&lt;BR /&gt;Name Age Department&lt;BR /&gt;John 39 Sales&lt;BR /&gt;Rob 61 Sales&lt;/P&gt;&lt;P&gt;Data set should be created under name "Marketing"&lt;BR /&gt;Name Age Department&lt;BR /&gt;Mary 29 Marketing&lt;BR /&gt;Toni 23 Marketing&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;Data set should be created under name "HR"&lt;BR /&gt;Name Age Department&lt;BR /&gt;Sam 32 HR&lt;BR /&gt;Georg 39 HR&lt;/P&gt;</description>
    <pubDate>Wed, 19 Jun 2019 07:32:23 GMT</pubDate>
    <dc:creator>dhruvakumar</dc:creator>
    <dc:date>2019-06-19T07:32:23Z</dc:date>
    <item>
      <title>Based on value dataset creation ..using macros.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567149#M11450</link>
      <description>&lt;P&gt;Hi All,&lt;BR /&gt;I have one dataset having different departments like sales,marketing,HR.&lt;BR /&gt;By using macros based on departments I need to create datasets&lt;BR /&gt;Means based on department sales , I have to create sales dataset and for marketing I need to create marketings...for sales one sale dataaset...&lt;/P&gt;&lt;P&gt;For instance the above we have 3 different departments .. It should create 3 different datasets..for n no.of departments ..it should create n no.of datasets&lt;/P&gt;&lt;P&gt;Please could help on this requirement...&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 06:53:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567149#M11450</guid>
      <dc:creator>dhruvakumar</dc:creator>
      <dc:date>2019-06-19T06:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: Based on value dataset creation ..using macros.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567150#M11451</link>
      <description>&lt;P&gt;What would each data set contain? Can you provide an example of what your data looks like?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Makes it much easier to help you&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 06:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567150#M11451</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-19T06:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: Based on value dataset creation ..using macros.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567155#M11452</link>
      <description>&lt;P&gt;DATASET EMPloyee having :&lt;BR /&gt;Name Age Department&lt;BR /&gt;John 39 Sales&lt;BR /&gt;Mary 29 Marketing&lt;BR /&gt;Sam 32 HR&lt;BR /&gt;Rob 61 Sales&lt;BR /&gt;Toni 23 Marketing&lt;BR /&gt;Georg 39 HR&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The desired output should be&lt;/P&gt;&lt;P&gt;Data set should be created under name "sales"&lt;BR /&gt;Name Age Department&lt;BR /&gt;John 39 Sales&lt;BR /&gt;Rob 61 Sales&lt;/P&gt;&lt;P&gt;Data set should be created under name "Marketing"&lt;BR /&gt;Name Age Department&lt;BR /&gt;Mary 29 Marketing&lt;BR /&gt;Toni 23 Marketing&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;Data set should be created under name "HR"&lt;BR /&gt;Name Age Department&lt;BR /&gt;Sam 32 HR&lt;BR /&gt;Georg 39 HR&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 07:32:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567155#M11452</guid>
      <dc:creator>dhruvakumar</dc:creator>
      <dc:date>2019-06-19T07:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: Based on value dataset creation ..using macros.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567156#M11453</link>
      <description>&lt;P&gt;Ok. Use a dynamic approach like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Name $ Age Department $20.;
datalines;
John 39 Sales
Mary 29 Marketing
Sam 32 HR
Rob 61 Sales
Toni 23 Marketing
Georg 39 HR
;

proc sort data=have;
   by Department;
run;

data _null_;
   if _n_=1 then do;
      if 0 then set have;                                   
      declare hash h(dataset:"have(obs=0)", multidata:'y'); 
      h.definekey('Department');
      h.definedata(all:'Y'); 
      h.definedone();                                           
   end;
   do until(last.Department);                                     
      set have;                                             
      by Department;
      h.add();                                                  
   end;
   h.output(dataset:Department);                                   
   h.clear();                                                   
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jun 2019 07:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567156#M11453</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-19T07:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: Based on value dataset creation ..using macros.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567157#M11454</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort
  data=employee (keep=department)
  out=control
  nodupkey
;
run;

data _null_;
call execute('data');
do until (eof1);
  set control end=eof1;
  call execute(' ' || department);
end;
call execute('; set employee; select(department);');
do until (eof2);
  set control end=eof2;
  call execute('when ("' || strip(department) || '") output ' || strip(department) || ';');
end;
call execute('end; run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jun 2019 07:48:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567157#M11454</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-19T07:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: Based on value dataset creation ..using macros.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567158#M11455</link>
      <description>&lt;P&gt;Hi Draycut,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for reply, is there any best way can done by using macros.Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 07:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567158#M11455</guid>
      <dc:creator>dhruvakumar</dc:creator>
      <dc:date>2019-06-19T07:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Based on value dataset creation ..using macros.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567159#M11456</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;wrote this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Splitting-a-SAS-data-set/ta-p/517960" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Splitting-a-SAS-data-set/ta-p/517960&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps that will help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 07:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567159#M11456</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-19T07:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: Based on value dataset creation ..using macros.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567163#M11457</link>
      <description>&lt;P&gt;Using a macro just for the sake of using a macro is not efficient; it often leads to convoluted and unnecessarily complicated code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that both &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;'s and my solution require only one pass through the source dataset in the split step.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 08:06:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567163#M11457</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-19T08:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: Based on value dataset creation ..using macros.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567172#M11458</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;,&amp;nbsp;not entirely sure here. But doesn't your code pass through the source data set 3 times? To my limited knowledge of Call Execute logic, you create three data steps that each execute after your 'data _null_' data step. And each of these data steps read the source data set once? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 09:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567172#M11458</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-19T09:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Based on value dataset creation ..using macros.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567194#M11462</link>
      <description>&lt;P&gt;My data _null_ will perform one iteration. In the first do loop, it supplies the data step names to the data statement. Then it starts a select() block, and in the second loop it creates the body of the select. Then it ends the select and the data step, and terminates.&lt;/P&gt;
&lt;P&gt;The created code looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data
  dept1
  dept2
  dept3
;
set employee;
select(department);
  when ("dept1") output dept1;
  when ("dept2") output dept2;
  when ("dept3") output dept3;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 09:57:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567194#M11462</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-19T09:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: Based on value dataset creation ..using macros.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567198#M11463</link>
      <description>&lt;P&gt;Ah yes, I missread &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Makes sense!&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 10:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567198#M11463</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-19T10:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Based on value dataset creation ..using macros.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567327#M11478</link>
      <description>&lt;P&gt;Why?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;You should BY statements to calculate independent summaries instead. Here's an example to calculate the mean of age (you didn't provide salary in your data set) by department into a new data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Name $ Age Department $20.;
datalines;
John 39 Sales
Mary 29 Marketing
Sam 32 HR
Rob 61 Sales
Toni 23 Marketing
Georg 39 HR
;

proc means data=have NWAY NOPRINT;
class department;
var age;
output out=dept_means mean=avg_age;
run;

proc print data=dept_means noobs label;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203162"&gt;@dhruvakumar&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi All,&lt;BR /&gt;I have one dataset having different departments like sales,marketing,HR.&lt;BR /&gt;By using macros based on departments I need to create datasets&lt;BR /&gt;Means based on department sales , I have to create sales dataset and for marketing I need to create marketings...for sales one sale dataaset...&lt;/P&gt;
&lt;P&gt;For instance the above we have 3 different departments .. It should create 3 different datasets..for n no.of departments ..it should create n no.of datasets&lt;/P&gt;
&lt;P&gt;Please could help on this requirement...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 15:33:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Based-on-value-dataset-creation-using-macros/m-p/567327#M11478</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-19T15:33:29Z</dc:date>
    </item>
  </channel>
</rss>

