Hi everybody, I have the following data: DATA FLAGDEMO;
INPUT ID YEAR_T0 FLAG_2008 FLAG_2009 FLAG_2010 FLAG_2011 FLAG_2012 FLAG_2013 FLAG_2014 /*DESIRED FLAGS*/ FLAG_2Y FLAG_3Y;
DATALINES;
1 2008 0 0 0 0 0 1 . 0 0
1 2009 0 0 0 0 0 1 . 0 0
1 2010 0 0 0 0 0 1 . 0 1
1 2011 0 0 0 0 0 1 . 1 1
1 2012 0 0 0 0 0 1 . 1 1
1 2013 0 0 0 0 0 1 . 1 1
2 2010 0 0 0 0 0 . 1 0 0
2 2011 0 0 0 0 0 . 1 0 1
2 2012 0 0 0 0 0 . 1 1 1
2 2013 0 0 0 0 0 . 1 1 1
2 2014 0 0 0 0 0 . 1 1 1
3 2009 0 1 . . . . . 1 1
3 2010 0 1 . . . . . 1 1
;
RUN; I need to create the /*DESIRED FLAGS*/ FLAG_2Y and FLAG_3Y (I inserted them manually to better explain what I want); these flags are equal to the maximum between FLAG_(n) and FLAG_(n+2) o FLAG_(n+3) for each YEAR_T0=n. So for example, if YEAR_T0=2008 i want FLAG_2Y to be the maximum between flag_2008, flag_2009,flag_2010. I tried several combination of %do and array but I can't figure out the correct sintax or logic. Examples of attempt: First Attempt %macro flag_year_v1(t0,t2);
data output;
set input;
if YEAR_T0=&T0. then flag_2y=max(FLAG_&t0.-FLAG_&t2.);
run;
%mend flag_year_v1;
%flag_year_v1(2008,2010);
%flag_year_v1(2009,2011);
%flag_year_v1(2010,2012);
%flag_year_v1(2011,2013);
%flag_year_v1(2012,2014);
%flag_year_v1(2013,2014);
%flag_year_v1(2014,2014); Second Attempt %MACRO FLAG_2Y_3Y(START,STOP);
%DO i=(&start.) %TO (&stop.);
%DO j=(&start.+2) %TO (&stop.);
%DO h=(&start.+3) %TO (&stop.);
DATA output;
SET input;
ARRAY FLAG_Y(*) FLAG_&i.-FLAG_&h.;
flag_default_2y=max(FLAG_Y(&i.)-FLAG_Y(&j.));
flag_default_3y=max(FLAG_Y(&i.)-FLAG_Y(&h.));
%END;
%END;
%END;
run;
%MEND FLAG_2Y_3Y;
%FLAG_2Y_3Y(2008,2014); As much as i try, I can't obtain my desired results, and I would like to write a code similar to the second but I am not super proficient with iteratives loop. Hope somebody can help me
... View more