The data step will work fine if you give it the same input, DISTINCT_MONTHS, as you gave the SQL query.
But you should not need to use the COMPRESS() function. Just use the CATS() function.
data _null_;
set distinct_months;
n+1;
call symputx(cats("year",n), year);
call symputx(cats("month",n), month);
run;
If the goal is just to make the macro variables then skip making the dataset.
proc sql noprint;
select distinct year, put(month,z2.)
into :year1- , :month1-
from months
order by year , month
;
quit;
... View more