I'm trying to define a macro variable (state) that is defendant on the date. Here's what I have now....
DATA _NULL_;
IF "&sysdate."D - 36 IN ("01JAN2018"d,"02JAN2018"d,"15JAN2018"d,"19FEB2018"d,"28MAY2018"d,"04JUL2018"d
,"05JUL2018"d,"03SEP2018"d,"11NOV2018"d,"22NOV2018"d,"25DEC2018"d,"26DEC2018"d) THEN DO;
%LET state = 'LA','MS','AL','UT','RI';
END;
ELSE IF "&sysdate."D - 36 IN ("08OCT2018"d) THEN DO;
%LET state= 'LA','AL','UT','RI';
END;
ELSE IF "&sysdate."D - 36 IN ("13FEB2018"d,"03JUN2018"d) THEN DO;
%LET state= 'LA','AL';
END;
ELSE IF "&sysdate."D - 36 IN ("23APR2018"d) THEN DO;
%LET state= 'MS','AL';
END;
ELSE IF "&sysdate."D - 36 IN ("06NOV2018"d) THEN DO;
%LET state= 'LA','RI';
END;
ELSE IF "&sysdate."D - 36 IN ("08JAN2018"d,"19JAN2018"d,"30MAR2018"d,"01APR2018"d,"30AUG2018"d
,"01NOV2018"d,"23NOV2018"d,"24DEC2018"d,"31DEC2018"d) THEN DO;
%LET state= 'LA';
END;
ELSE IF "&sysdate."D - 36 IN ("13AUG2018"d,"04MAY2018"d) THEN DO;
%LET state= 'RI';
END;
ELSE IF "&sysdate."D - 36 IN ("24JUL2018"d) THEN DO;
%LET state= 'UT';
END;
RUN;
This is returning state = 'UT' but I want it to return state = 'LA','MS','AL','UT','RI' since "&sysdate."D - 36 = "02JAN2018"d
Appreciate any help you can provide
Use call symput rather than %let! I think that the following does what you want:
DATA _NULL_; IF "&sysdate."D - 36 IN ("01JAN2018"d,"02JAN2018"d,"15JAN2018"d,"19FEB2018"d,"28MAY2018"d,"04JUL2018"d ,"05JUL2018"d,"03SEP2018"d,"11NOV2018"d,"22NOV2018"d,"25DEC2018"d,"26DEC2018"d) THEN DO; /* %LET state = 'LA','MS','AL','UT','RI'; */ call symput('state',"'LA','MS','AL','UT','RI'"); END; ELSE IF "&sysdate."D - 36 IN ("08OCT2018"d) THEN DO; /* %LET state= 'LA','AL','UT','RI'; */ call symput('state',"'LA','AL','UT','RI'"); END; ELSE IF "&sysdate."D - 36 IN ("13FEB2018"d,"03JUN2018"d) THEN DO; /* %LET state= 'LA','AL'; */ call symput('state',"'LA','AL'"); END; ELSE IF "&sysdate."D - 36 IN ("23APR2018"d) THEN DO; /* %LET state= 'MS','AL'; */ call symput('state',"'MS','AL'"); END; ELSE IF "&sysdate."D - 36 IN ("06NOV2018"d) THEN DO; /* %LET state= 'LA','RI'; */ call symput('state',"'LA','RI'"); END; ELSE IF "&sysdate."D - 36 IN ("08JAN2018"d,"19JAN2018"d,"30MAR2018"d,"01APR2018"d,"30AUG2018"d ,"01NOV2018"d,"23NOV2018"d,"24DEC2018"d,"31DEC2018"d) THEN DO; /* %LET state= 'LA'; */ call symput('state',"'LA'"); END; ELSE IF "&sysdate."D - 36 IN ("13AUG2018"d,"04MAY2018"d) THEN DO; /* %LET state= 'RI'; */ call symput('state',"'RI'"); END; ELSE IF "&sysdate."D - 36 IN ("24JUL2018"d) THEN DO; /* %LET state= 'UT'; */ call symput('state',"'UT'"); END; RUN; %put &state.;
Art, CEO, AnalystFinder.com
Use call symput rather than %let! I think that the following does what you want:
DATA _NULL_; IF "&sysdate."D - 36 IN ("01JAN2018"d,"02JAN2018"d,"15JAN2018"d,"19FEB2018"d,"28MAY2018"d,"04JUL2018"d ,"05JUL2018"d,"03SEP2018"d,"11NOV2018"d,"22NOV2018"d,"25DEC2018"d,"26DEC2018"d) THEN DO; /* %LET state = 'LA','MS','AL','UT','RI'; */ call symput('state',"'LA','MS','AL','UT','RI'"); END; ELSE IF "&sysdate."D - 36 IN ("08OCT2018"d) THEN DO; /* %LET state= 'LA','AL','UT','RI'; */ call symput('state',"'LA','AL','UT','RI'"); END; ELSE IF "&sysdate."D - 36 IN ("13FEB2018"d,"03JUN2018"d) THEN DO; /* %LET state= 'LA','AL'; */ call symput('state',"'LA','AL'"); END; ELSE IF "&sysdate."D - 36 IN ("23APR2018"d) THEN DO; /* %LET state= 'MS','AL'; */ call symput('state',"'MS','AL'"); END; ELSE IF "&sysdate."D - 36 IN ("06NOV2018"d) THEN DO; /* %LET state= 'LA','RI'; */ call symput('state',"'LA','RI'"); END; ELSE IF "&sysdate."D - 36 IN ("08JAN2018"d,"19JAN2018"d,"30MAR2018"d,"01APR2018"d,"30AUG2018"d ,"01NOV2018"d,"23NOV2018"d,"24DEC2018"d,"31DEC2018"d) THEN DO; /* %LET state= 'LA'; */ call symput('state',"'LA'"); END; ELSE IF "&sysdate."D - 36 IN ("13AUG2018"d,"04MAY2018"d) THEN DO; /* %LET state= 'RI'; */ call symput('state',"'RI'"); END; ELSE IF "&sysdate."D - 36 IN ("24JUL2018"d) THEN DO; /* %LET state= 'UT'; */ call symput('state',"'UT'"); END; RUN; %put &state.;
Art, CEO, AnalystFinder.com
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.