【发布时间】:2016-06-17 19:49:14
【问题描述】:
当我运行宏将来自多个文件的数据输入到一个 SAS 表中时,它会在下一次迭代开始时替换正在读取的每个数据集。因此,我在最终表格中剩下的唯一数据是我使用循环读取的最后一个文件。如何在每次读取迭代结束时附加输出表,以防止每次移动到下一个文件时丢失数据?
当前代码:
%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(&type,1);
%let yr=%scan(&year,1);
%let mnth=%scan(&months,1);
%let day=%scan(&days,&K);
/*Creates string variables for Export and import locations of files using macro loop variables*/
%let exportfile = "C:\Users\wwn\Documents\HistoricalRateTesting\Top&nmbr&yr&mnth&day&filetype";
%let src = "\\2119\Raw_Data\Transposed_Canvass\Top&nmbr&yr&mnth&day&filetype";
/*Imports All files in that Alpha, Year and Month Group*/
DATA work.RAW_DATA;
INFILE &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;
【问题讨论】:
-
你每次创建一个新的数据集 work.RAW_DATA 这种方式。只需为 k=1 创建一次,然后使用 proc append
-
也许这会有所帮助。您似乎找到了约会问题的答案? communities.sas.com/t5/SAS-Communities-Library/…