You need to figure out what that monster is actually trying to do. Then you could probably do it without any macro code at all. It looks like you are scanning through a series of variables and looking for specific value and when it is found the program sets some value into the newly generated variable. It is not clear to me what that value you is, but it feels like it is the date that was built into the variable name. This is a process that should use an array. Then the logic with the INTNX can be used to calculate the indexed into the array. It looks like your variables are named such that it might require extra effort to generate the names of the variables to include in the array. But let's say you had nice variable names then your code might look something like this. * Make some dummy data ; data have; array months DATEFIELD_200501 DATEFIELD_201205 DATEFIELD_201301 ; input _n_ @@; months(_n_)=2 ; cards; 1 2 3 2 1 run; data want; set have; array months DATEFIELD_200501 -- DATEFIELD_201301 ; RESULT_DATE = . ; format result_date yymmdd10. ; do i=1 to dim(months) while (missing(result_date)); if months(i) = 2 then result_date = input(substr(vname(months(i)),11,6)||'01',yymmdd8.) ; end; run; DATEFIELD_ DATEFIELD_ DATEFIELD_ RESULT_ Obs 200501 201205 201301 DATE i 1 2 . . 2005-01-01 2 2 . 2 . 2012-05-01 3 3 . . 2 2013-01-01 4 4 . 2 . 2012-05-01 3 5 2 . . 2005-01-01 2
... View more