title: SAS Using a DO loop to read in multiple files but need to append the table in each iteration to prevent losing data
body: <p>When I run my macros to input data from multiple files into one SAS table, it is replacing each dataset that is being read in once the next iteration begins.  Thus, the only data that I am left with in my final table is the last file that I read in with the loop. How can I append my output table at the end of each read in iteration to prevent losing data each time I move to the next file?</p>
  
  <p>Current Code:</p>
  
  <pre><code>  %let type=40;
  
  %let year=2015;
  
  %let months =07;
  
  %let days = 01 02 03 04 05  06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31;
  
  %let filetype=.csv;
  
  
  
  %macro import_files;
  
  
                      %do K=1 %to 31; /*day*/
  
                             /*Scans through Macro Variable Arrays to find current month, year and letter group*/
  
                             %let nmbr = %scan(&amp;type,1);
  
                             %let yr=%scan(&amp;year,1);
  
                             %let mnth=%scan(&amp;months,1);
  
                             %let day=%scan(&amp;days,&amp;K);
  
  
  
                             /*Creates string variables for Export and import locations of files using macro loop variables*/
  
                             %let exportfile = "C:\Users\wwn\Documents\HistoricalRateTesting\Top&amp;nmbr&amp;yr&amp;mnth&amp;day&amp;filetype";
  
                             %let src = "\\2119\Raw_Data\Transposed_Canvass\Top&amp;nmbr&amp;yr&amp;mnth&amp;day&amp;filetype";
  
  
                             /*Imports All files in that Alpha, Year and Month Group*/
  
                             DATA work.RAW_DATA;
  
                                  INFILE &amp;src firstobs=3 LRECL=1000 DELIMITER=',' TRUNCOVER DSD;
  /*                              informat arv_dt mmddyy10. shop_dttm DATETIME18. arv_tm time5. rtrn_tm time5.;*/
  /*                              format shop_dttm DATETIME18. arv_tm time5. rtrn_tm time5.;*/
  
                                  INPUT
  
                                       city_cd          : $CHAR3.
  
                                       rtrn_city_cd     : $CHAR3.
  
                                       shop_car_type_cd : $CHAR4.
  
                                       shop_rt_categ    :  $CHAR2.
  
                                       shop_rt_type     :  $CHAR1.
  
                                       lor              : ?? BEST2.
  
                                       arv_tm           : ?? TIME5.
  
                                       rtrn_tm          : ??TIME5.
  
                                       arv_dt           : ?? MMDDYY10.
  
                                       shop_dttm        : ANYDTDTM.
  
                                       Brand_ZE         : ?? BEST10.2
  
                                       Brand_ZI         : ?? BEST10.2
  
                                       Brand_ZL         : ?? BEST10.2
  
                                       Brand_ZD         : ?? BEST10.2
  
                                       Brand_AL         : ?? BEST10.2
  
                                       Brand_ZR         : ?? BEST10.2
  
                                       Brand_ET         : ?? BEST10.2
  
                                       Brand_ZT         : ?? BEST10.2
  
                                       Brand_AD         : ?? BEST10.2
  
                                       Brand_ZA         : ?? BEST10.2
  
                                       Brand_EZ         : ?? BEST10.2
  
                                       Brand_SX         : ?? BEST10.2
  
                                       Brand_FX         : ?? BEST10.2
  
                                       Brand_FF         : ?? BEST10.2;
  
                  RUN;
  
                                      %end;
  
                                       %mend import_files;
                                       %import_files;
  </code></pre>