Thank you for all your input, I know you guys know better ways. As I said, this code is just part of a bigger MACRO. I don't know if this makes sense to you, but I am posting the overall code. The code needs to be repeated for a dozen of times to produce a dozen datafile at the end as part of my report. See if you can spot the problem or make it better. I run it, every thing else works but the "Array" function.
%MACRO SYS (SYS, OUTFILE); proc freq data=zip noprint; table year*birthzip/norow nocol nopercent out=zipct; where syst=&SYS; run;
proc sort data=zipct; by birthzip year; run;
proc transpose data=zipct out=zip_w; var count; by birthzip; id year; run;
data zip_w; set zip_w; array num[*] _numeric_; %do i=1 %to %sysfunc(countw(num)); %if num[i]=. %then num[i]=0; %end; drop _LABEL_ _NAME_ i; _96_00=sum(_1996, _1997, _1998, _1999, _2000); _01_05=sum(_2001, _2002, _2003, _2004, _2005); _06_10=sum(_2006, _2007, _2008, _2009, _2010); _11_16=sum(_2011, _2012, _2013, _2014, _2015, _2016); Total=SUM(_1996, _1997,_1998, _1999, _2000, _2001, _2002, _2003, _2004, _2005, _2006, _2007, _2008, _2009, _2010, _2011, _2012, _2013, _2014, _2015, _2016); run;
data zip_w; retain birthzip Total _1996 _1997 _1998 _1999 _2000 _2001 _2002 _2003 _2004 _2005 _2006 _2007 _2008 _2009 _2010 _2011 _2012 _2013 _2014 _2015 _2016 ; set zip_w; run;
PROC SORT DATA=ZIP_W OUT=&OUTFILE; BY DESCENDING Total ; RUN;
PROC EXPORT DATA=&OUTFILE OUTFILE="\\ACCIT2\ZIP\&OUTFILE" dbms=csv replace; RUN; %MEND;
... View more