Hi all, I have some population data from 2007 to 2017 (one table for each year) and I'm trying to create a macro that creates a table for each year with an id, muncipality of residence and muncipality of residense for each of the following four years and merge them together in one table. Here is my code (I'm using SAS 9.4 if that makes any difference): %macro sqlloop(start, end); proc sql; %do year0=&start. %to end; %let year1=%eval(year0+1); %let year2=%eval(year0+2); %let year3=%eval(year0+3); %let year4=%eval(year0+4); proc sql; create table mun&year0. as select t1.id, t1.mun as mun&year0., t2.mun as mun&year1., t3.mun as mun&year2., t4.mun as mun&year3., t5.mun as mun&year4., &year0. as year from pop&year0. as t1 left join pop&year1. as t2 on t1.id = t2.id left join pop&year2. as t3 on t1.id = t3.id left join pop&year3. as t4 on t1.id = t4.id left join pop&year4. as t5 on t1.id = t5.id order by id; %end; quit; %mend; %sqlloop(start=2007, end=2017) data mun07_2017; set mun2007 mun2008 mun2009 mun2010 mun2011 mun2012 mun2013 mun2014 mun2015 mun2016 mun2017; run; The problem that I have is that the macro stops after 2013, because it can't find a table for 2018 (residence 4 years after), which of course doesn't exist. Therefore, I want a condition that sets residence as missing if the corresponding table doesn't exist. I have already tried multiple solutions, but nothing have worked for me so far. Hope you can help!
... View more