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
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.