<?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: Exporting by group automatically. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Exporting-by-group-automatically/m-p/674402#M203083</link>
    <description>&lt;P&gt;While I think&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;is mostly right when he states that splitting datasets is often a waste of time, sometimes you still have to. For instance if you are mailing or otherwise forwarding data to specific departments (or customers), and they are not supposed to get the data for the other departments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A simple solution for creating multiple datasets goes something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Create a solution that works for a single value of the parameter, e.g.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want3007;
  set have;
  where IEE=3007;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Make that into a macro, using the parameter:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro extract(IEE);
  data want&amp;amp;IEE;
    set have;
    where IEE=&amp;amp;IEE;
  run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3. Test the macro with a single, known parameter:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint; /* lets you see the code generated in the log */
%extract(3007);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;4. Use SQL to put all the macro calls into a single macro variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct cats('%extract(',IEE,')') into :doit separated by ';'
  from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;5. Execute that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;doit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 04 Aug 2020 15:39:25 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2020-08-04T15:39:25Z</dc:date>
    <item>
      <title>Exporting by group automatically.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-by-group-automatically/m-p/674290#M203018</link>
      <description>&lt;P&gt;Hello there. I'm looking for a little help with exporting some data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set that contains all records where a variable named "IEE" matches to a top ten count which will change every time its ran. The variable is numeric and always 4 numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample Is&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IEE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Var1&amp;nbsp; &amp;nbsp;Var2&lt;/P&gt;&lt;P&gt;111&amp;nbsp; &amp;nbsp; &amp;nbsp; 3007&amp;nbsp; &amp;nbsp; &amp;nbsp;Red&amp;nbsp; &amp;nbsp;Tree&lt;/P&gt;&lt;P&gt;222&amp;nbsp; &amp;nbsp; &amp;nbsp;3007&amp;nbsp; &amp;nbsp; &amp;nbsp;Red&amp;nbsp; &amp;nbsp; House&lt;/P&gt;&lt;P&gt;333&amp;nbsp; &amp;nbsp; &amp;nbsp;3007&amp;nbsp; &amp;nbsp; &amp;nbsp;Blue&amp;nbsp; &amp;nbsp;Car&lt;/P&gt;&lt;P&gt;444&amp;nbsp; &amp;nbsp; &amp;nbsp;4333&amp;nbsp; &amp;nbsp; &amp;nbsp;Red&amp;nbsp; &amp;nbsp; Car&lt;/P&gt;&lt;P&gt;555&amp;nbsp; &amp;nbsp; &amp;nbsp;4333&amp;nbsp; &amp;nbsp; &amp;nbsp;Red&amp;nbsp; &amp;nbsp; Tree&lt;/P&gt;&lt;P&gt;666&amp;nbsp; &amp;nbsp; &amp;nbsp;4333&amp;nbsp; &amp;nbsp; &amp;nbsp;Red&amp;nbsp; &amp;nbsp; Tree&lt;/P&gt;&lt;P&gt;777&amp;nbsp; &amp;nbsp; &amp;nbsp;5544&amp;nbsp; &amp;nbsp; &amp;nbsp;Red&amp;nbsp; &amp;nbsp; House&lt;/P&gt;&lt;P&gt;888&amp;nbsp; &amp;nbsp; &amp;nbsp;5544&amp;nbsp; &amp;nbsp; &amp;nbsp;Red&amp;nbsp; &amp;nbsp; House&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What i'm trying to achieve is I want the code to automatically create a separate dataset for each of the values in variable IEE so while i have a top 10 if we were to run it on the above sample we would have 3 datasets.&lt;BR /&gt;&lt;BR /&gt;one for 3007 containing 3 observations&lt;/P&gt;&lt;P&gt;one for 4333 containing 3 observations&amp;nbsp;&lt;/P&gt;&lt;P&gt;one for 5544 containing 2 observations&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not too fussed what the output datasets are called as long as they're identifiable (probably sensible to name them the IEE value)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm pretty sure this needs to go in a macro but i cant quite figure it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help greatly appreciated&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 09:03:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-by-group-automatically/m-p/674290#M203018</guid>
      <dc:creator>Stret</dc:creator>
      <dc:date>2020-08-04T09:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting by group automatically.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-by-group-automatically/m-p/674291#M203019</link>
      <description>&lt;P&gt;Splitting datasets is, in most cases, not needed and only causes extra work. You can extract a subset for a given analysis by using a WHERE condition, and you can use BY group processing to repeat a certain analysis fior groups in one step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If, on the other hand, you need to &lt;EM&gt;export&lt;/EM&gt; data to a different environment and, say, for different people, you can also use BY group processing to automatically create a separate &lt;EM&gt;file&lt;/EM&gt; for each group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the question is: what do you really want to do with those subsets?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 09:19:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-by-group-automatically/m-p/674291#M203019</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-04T09:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting by group automatically.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-by-group-automatically/m-p/674293#M203021</link>
      <description>Hello Kurt.&lt;BR /&gt;&lt;BR /&gt;Thank you for responding.&lt;BR /&gt;&lt;BR /&gt;Because I always have a "top 10" ive just created this&lt;BR /&gt;&lt;BR /&gt;data work.Split_&amp;amp;Pos_Entry;&lt;BR /&gt;set work.Top10_trans_&amp;amp;Pos_Entry;&lt;BR /&gt;by IEE;&lt;BR /&gt;retain ID 0;&lt;BR /&gt;if first.IEE then ID = ID + 1;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;this has given me a data set with an ID 1 to 10 thus grouping each of the IEE's I "think" im ont he right track here.&lt;BR /&gt;&lt;BR /&gt;what i now need to happen is&lt;BR /&gt;&lt;BR /&gt;if id = 1 then output to DATAset_1&lt;BR /&gt;if id = 2 then output to DATAset_2&lt;BR /&gt;&lt;BR /&gt;%macro IEEFraud(Pos_Entry= );&lt;BR /&gt;&lt;BR /&gt;Here's my full current code if this helps me explain better&lt;BR /&gt;&lt;BR /&gt;proc sql outobs=10;&lt;BR /&gt;&lt;BR /&gt;create table Top10_&amp;amp;Pos_Entry as&lt;BR /&gt;select Distinct MERCHANT_CATEGORY_XCD,&lt;BR /&gt;TRANSACTN_POSTING_ETRY_XFLG,&lt;BR /&gt;count(MERCHANT_CATEGORY_XCD) as Count,&lt;BR /&gt;sum(TRANSACTION_AMT) as Sum_Total&lt;BR /&gt;&lt;BR /&gt;from Data.GET_TRANSACTIONS&lt;BR /&gt;&lt;BR /&gt;Where TRANSACTN_POSTING_ETRY_XFLG = "&amp;amp;Pos_Entry"&lt;BR /&gt;and TRANSACTION_FRAUD_TYPE_CD = "CONFIRMED_FRAUD"&lt;BR /&gt;&lt;BR /&gt;Group by 1&lt;BR /&gt;Order By Sum_Total DESC&lt;BR /&gt;&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;&lt;BR /&gt;create table Top10_Trans_&amp;amp;Pos_Entry as&lt;BR /&gt;select&lt;BR /&gt;&lt;BR /&gt;Auth.FI_TRANSACTION_ID,&lt;BR /&gt;Auth.PAN,&lt;BR /&gt;Auth.TRANSACTION_dttm,&lt;BR /&gt;Auth.MERCHANT_CATEGORY_XCD as IEE,&lt;BR /&gt;Auth.TRANSACTION_AMT,&lt;BR /&gt;Auth.TRANSACTN_POSTING_ETRY_XFLG,&lt;BR /&gt;Auth.AUTH_SECONDARY_VERIFY_XCD as Secure,&lt;BR /&gt;Auth.Decision_XCD as Host_Decision,&lt;BR /&gt;Auth.MODEL_SCR,&lt;BR /&gt;Auth.TRANSACTION_FRAUD_TYPE_CD,&lt;BR /&gt;&lt;BR /&gt;case when&lt;BR /&gt;TRANSACTION_FRAUD_TYPE_CD = "CONFIRMED_FRAUD" then 1&lt;BR /&gt;else 0&lt;BR /&gt;end as Fraud_Flag&lt;BR /&gt;&lt;BR /&gt;from Data.GET_TRANSACTIONS as auth&lt;BR /&gt;Inner join work.Top10_&amp;amp;Pos_Entry as IEE on auth.MERCHANT_CATEGORY_XCD = IEE.MERCHANT_CATEGORY_XCD and auth.TRANSACTN_POSTING_ETRY_XFLG = IEE.TRANSACTN_POSTING_ETRY_XFLG&lt;BR /&gt;order by IEE;&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;data work.Split_&amp;amp;Pos_Entry;&lt;BR /&gt;set work.Top10_trans_&amp;amp;Pos_Entry;&lt;BR /&gt;by IEE;&lt;BR /&gt;retain ID 0;&lt;BR /&gt;if first.IEE then ID = ID + 1;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%mend IEEFraud;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%IEEFraud(Pos_Entry= E)&lt;BR /&gt;%IEEFraud(Pos_Entry= K)&lt;BR /&gt;%IEEFraud(Pos_Entry= S)&lt;BR /&gt;%IEEFraud(Pos_Entry= F)&lt;BR /&gt;%IEEFraud(Pos_Entry= V)</description>
      <pubDate>Tue, 04 Aug 2020 09:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-by-group-automatically/m-p/674293#M203021</guid>
      <dc:creator>Stret</dc:creator>
      <dc:date>2020-08-04T09:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting by group automatically.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-by-group-automatically/m-p/674294#M203022</link>
      <description>&lt;P&gt;And what will you do with the end results of this?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 09:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-by-group-automatically/m-p/674294#M203022</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-04T09:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting by group automatically.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-by-group-automatically/m-p/674402#M203083</link>
      <description>&lt;P&gt;While I think&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;is mostly right when he states that splitting datasets is often a waste of time, sometimes you still have to. For instance if you are mailing or otherwise forwarding data to specific departments (or customers), and they are not supposed to get the data for the other departments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A simple solution for creating multiple datasets goes something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Create a solution that works for a single value of the parameter, e.g.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want3007;
  set have;
  where IEE=3007;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Make that into a macro, using the parameter:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro extract(IEE);
  data want&amp;amp;IEE;
    set have;
    where IEE=&amp;amp;IEE;
  run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3. Test the macro with a single, known parameter:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint; /* lets you see the code generated in the log */
%extract(3007);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;4. Use SQL to put all the macro calls into a single macro variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct cats('%extract(',IEE,')') into :doit separated by ';'
  from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;5. Execute that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;doit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Aug 2020 15:39:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-by-group-automatically/m-p/674402#M203083</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-08-04T15:39:25Z</dc:date>
    </item>
  </channel>
</rss>

