Hi, I'm having some issues trying to write the syntax for this macro. Basically, what I want it to do is to calculate _date variable if one or the other variable exists. For example, certain datasets have the --DTC variable and certain datasets have --STDTC variable. I want the code to calculate _date if the dataset has --DTC variable, but if the dataset doesn't have the --DTC variable then the _date variable is calculated using --STDTC variable. Currently, it's failing because of the first condition where I have set &dsn.dtc is causing _date to not be calculated because the dataset I have does not have DTC but instead has --STDTC. %macro util_generate_epoch(dsn= ); data ec; set c373_un.ec(keep=usubjid ecstdtc); ECSTD=substr(ecstdtc,1,10); _ECSTD=input(ecstd,yymmdd10.); format _ecstd yymmdd10.; drop ecstdtc ECSTD; run; proc sort data=ec; by usubjid; run; proc sort data=&dsn.; by usubjid; run; data test; length EPOCH $30; merge &dsn.(in=a) ec(in=b); by usubjid; if a; %if &dsn.dtc ne '' %then %do; _date=substr(&dsn.DTC,1,10); %end; %else %if &dsn.stdtc ne '' %then %do; _date=substr(&dsn.stdtc,1,10); %end; _date2=input(_date,yymmdd10.); format _date2 yymmdd10.; _days=_ecstd-_date2 +1; if -42 <= _days < -21 then EPOCH="SCREENING"; else if -21 <= _days <=0 then EPOCH="BASELINE"; else if 0 < _days <= 730 then EPOCH="SHORT TERM FOLLOW-UP"; else if 730 < _days <= 2190 then EPOCH="LONG TERM FOLLOW-UP"; *drop _days _ecstd _date _date2; run; %mend; %util_generate_epoch(dsn=ae);
... View more