<?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: Multiple dynamic files from one file based on employee id in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-dynamic-files-from-one-file-based-on-employee-id/m-p/568712#M160149</link>
    <description>I'm unable to locate one example to match my requirement.&lt;BR /&gt;&lt;BR /&gt;It is the business requirement.&lt;BR /&gt;</description>
    <pubDate>Tue, 25 Jun 2019 11:49:59 GMT</pubDate>
    <dc:creator>Babloo</dc:creator>
    <dc:date>2019-06-25T11:49:59Z</dc:date>
    <item>
      <title>Multiple dynamic files from one file based on employee id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-dynamic-files-from-one-file-based-on-employee-id/m-p/568431#M160010</link>
      <description>I have to create multiple dynamic files based one single file which has employee id, reporting date and other variables. If the file has 10 different employee ids and reporting date then it should create 10 files.&lt;BR /&gt;&lt;BR /&gt;As is :&lt;BR /&gt;&lt;BR /&gt;Emp_ID reporting_dt idv&lt;BR /&gt;100000 17mar2019  31&lt;BR /&gt;100001  21may2018 36&lt;BR /&gt;100000  17mar2019  32&lt;BR /&gt;&lt;BR /&gt;To be:&lt;BR /&gt;&lt;BR /&gt;File1 should have&lt;BR /&gt;&lt;BR /&gt;Emp_id  reporting_dt  idv&lt;BR /&gt;100000  17mar2019   31&lt;BR /&gt;100000  17mar2019  32&lt;BR /&gt;&lt;BR /&gt;File 2 should have&lt;BR /&gt;&lt;BR /&gt;Emp_id reporting_dt  idv&lt;BR /&gt;100001 21may2018 36&lt;BR /&gt;</description>
      <pubDate>Mon, 24 Jun 2019 17:02:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-dynamic-files-from-one-file-based-on-employee-id/m-p/568431#M160010</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-06-24T17:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple dynamic files from one file based on employee id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-dynamic-files-from-one-file-based-on-employee-id/m-p/568434#M160013</link>
      <description>&lt;P&gt;What for? You can always use where conditions to use only a needed subset, or use by-group processing to do all analysis in one step.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2019 17:10:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-dynamic-files-from-one-file-based-on-employee-id/m-p/568434#M160013</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-24T17:10:45Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple dynamic files from one file based on employee id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-dynamic-files-from-one-file-based-on-employee-id/m-p/568435#M160014</link>
      <description>&lt;P&gt;If the report is to Excel or PDF and has specific formatting, consider this approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Create a program that does it for one person/employee&lt;/P&gt;
&lt;P&gt;2. Make it generic for all other employee's by turning it into a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&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;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this is to a text file (csv, txt, dat) with limited formatting, then you can do that in a single data step. The documentation on the FILENAME statement has an example of how to dynamically write to different output files. I'll assume you can navigate the documentation yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I have to create multiple dynamic files based one single file which has employee id, reporting date and other variables. If the file has 10 different employee ids and reporting date then it should create 10 files.&lt;BR /&gt;&lt;BR /&gt;As is :&lt;BR /&gt;&lt;BR /&gt;Emp_ID reporting_dt idv&lt;BR /&gt;100000 17mar2019 31&lt;BR /&gt;100001 21may2018 36&lt;BR /&gt;100000 17mar2019 32&lt;BR /&gt;&lt;BR /&gt;To be:&lt;BR /&gt;&lt;BR /&gt;File1 should have&lt;BR /&gt;&lt;BR /&gt;Emp_id reporting_dt idv&lt;BR /&gt;100000 17mar2019 31&lt;BR /&gt;100000 17mar2019 32&lt;BR /&gt;&lt;BR /&gt;File 2 should have&lt;BR /&gt;&lt;BR /&gt;Emp_id reporting_dt idv&lt;BR /&gt;100001 21may2018 36&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2019 17:16:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-dynamic-files-from-one-file-based-on-employee-id/m-p/568435#M160014</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-24T17:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple dynamic files from one file based on employee id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-dynamic-files-from-one-file-based-on-employee-id/m-p/568490#M160030</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I second&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;'s "what for?" notion. But if you really need it, there're many ways. One is to index the file by EMP_ID to enable BY processing (instead of sorting the whole thing) and then use a hash to split it dynamically:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                       
  input Emp_ID rpt_dt:date. idv ;                 
  cards ;                                         
100003 31dec2018 33                               
100001 21may2018 31                               
100003 31dec2018 33                               
100002 01jun2018 32                               
100003 11aug2018 33                               
100002 15dec2018 32                               
run ;                                             
                                                  
proc sql ;                                        
  create index emp_id on have (emp_id) ;          
quit ;                                            
                                                  
data _null_ ;                                     
  if _n_ = 1 then do ;                            
    dcl hash h() ;                                
    h.definekey ("_n_") ;                         
    h.definedata ("emp_id", "rpt_dt", "idv") ;    
    h.definedone () ;                             
  end ;                                           
  do _n_ = 1 by 1 until (last.emp_id) ;           
    set have ;                                    
    by emp_id ;                                   
    h.add() ;                                     
  end ;                                           
  h.output (dataset: catx ("_", "have", emp_id)) ;
  h.clear() ;                                     
run ;                                             
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A more traditional, 2-pass, approach is (1) create a list of unique EMP_ID values on the first pass and (2) generate code with the case structure (or an IF-THEN-ELSE series). This, too, can be done in an infinite number of ways. Here's one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;                                                                                
  dcl hash h (dataset:"have", ordered:"A") ;                                                 
  h.definekey ("emp_id") ;                                                                   
  h.definedone() ;                                                                           
  dcl hiter hi ("h") ;                                                                       
  call execute ("data ") ;                                                                   
  do while (hi.next() = 0) ;                                                                 
    call execute (catx ("_", "have", emp_id)) ;                                              
  end ;                                                                                      
  call execute ("; set have ; select (emp_id) ;") ;                                          
  do while (hi.next() = 0) ;                                                                 
    call execute (catx (" ", "when (", emp_id, ") output", catx ("_", "have", emp_id),";")) ;
  end ;                                                                                      
  call execute ("otherwise ; end ; run ;") ;                                                 
  stop ;                                                                                     
  set have ;                                                                                 
run ;                                                                                        
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or, if you prefer SQL to the hash object:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint ;                                                                                                              
  select distinct catx ("_", "have", emp_id) into :filelist separated by " " from have ;                                        
  select distinct catx (" ", "when (", emp_id, ") output", catx ("_", "have", emp_id)) into :select separated by ";" from have ;
quit ;                                                                                                                          
                                                                                                                                
data &amp;amp;filelist ;                                                                                                                
  set have ;                                                                                                                    
  select (emp_id) ;                                                                                                             
   &amp;amp;select ;                                                                                                                    
   otherwise ;                                                                                                                  
  end ;                                                                                                                         
run ;                                                                                                                           
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2019 18:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-dynamic-files-from-one-file-based-on-employee-id/m-p/568490#M160030</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-06-24T18:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple dynamic files from one file based on employee id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-dynamic-files-from-one-file-based-on-employee-id/m-p/568712#M160149</link>
      <description>I'm unable to locate one example to match my requirement.&lt;BR /&gt;&lt;BR /&gt;It is the business requirement.&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Jun 2019 11:49:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-dynamic-files-from-one-file-based-on-employee-id/m-p/568712#M160149</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-06-25T11:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple dynamic files from one file based on employee id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-dynamic-files-from-one-file-based-on-employee-id/m-p/568717#M160152</link>
      <description>&lt;P&gt;See this example (I posted almost exactly the same code less than two weeks ago, IIRC)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input emp_id $ reporting_dt :date9. idv;
format reporting_dt yymmddd10.;
datalines;
100000 17mar2019 31
100001 21may2018 36
100000 17mar2019 32
;

proc sort
  data=have (keep=emp_id)
  out=control
  nodupkey
;
by emp_id;
run;

data _null_;
call execute('data');
do until (eof1);
  set control end=eof1;
  call execute(cats(' EMP_',emp_id));
end;
call execute('; set have; select(emp_id);');
do until (eof2);
  set control end=eof2;
  call execute('when ("' !! strip(emp_id) !! '") output EMP_' !! strip(emp_id) !! ';');
end;
call execute('end; run;');
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jun 2019 12:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-dynamic-files-from-one-file-based-on-employee-id/m-p/568717#M160152</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-25T12:14:08Z</dc:date>
    </item>
  </channel>
</rss>

