data _null_;
LMTE=intnx('Month',&pbd_date,-1,'b');
CALL SYMPUT('BegDate', PUT( LMTE,date9.));
run;
%put &BegDate;
This date macro resolves to 01NOV2015 which is the first day of last month. Note &pbd_date is a calendar defined variable that assigns the current date, in this case -1 month
Now when I use &BegDate in the script such as
data Decisioned_In_Time_ (keep = ln_no
d_lm_workout_type
lm_referral_cd
ln_lol_msg_xx
lol_rec_chng_dt
bkr_status_cd
bkr_setup_dt
bkr_removal_dt
_385_to_Decision
/* Trial_Doc_Prep_to_Street*/
/* Final_Doc_Prep_to_Street*/
/* Tri_or_Fin_Doc_to_Str_3pl_days*/
d_lm_reject_fail_dt
lm_removal_dt
lm_status_cd)
;
retain ln_no
Critical_Step
Critical_nm
lm_removal_dt;
merge Dors_Mtg_daily (where = (d_lm_negotiation_dt ne .
and not(index(d_lm_workout_status,'NEGOTIATION'))
and (d_lm_rp_fb_to_doc_prep_dt >= &BegDate.
or d_lm_qa_trial_dt >= &BegDate.
or d_lm_workout_approved_dt >= &BegDate.
or d_lm_trial_doc_prep_qa_dt >= &BegDate.
or d_lm_trial_on_street_dt >= &BegDate.
or d_lm_verbal_accept_dt >= &BegDate.
or d_lm_workout_trial_start_dt >= &BegDate.
or d_lm_final_review_dt >= &BegDate.
or d_lm_qa_final_dt >= &BegDate.
or d_lm_final_approved_dt >= &BegDate.
or d_lm_final_doc_prep_qa_dt >= &BegDate.
or d_lm_final_on_street_dt >= &BegDate.
or d_lm_settled_pend_funds_dt >= &BegDate.
or d_lm_workout_fulfill_dt >= &BegDate.
or d_lm_reject_fail_dt >= &BegDate.
or lm_removal_dt >= &BegDate.)
run;
NOTE: Line generated by the macro variable "BEGDATE".
01NOV2015
-------
22
76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, AND, EQ, GE, GT, LE, LT, NE, OR, ^=,
|, ||, ~=.
ERROR 76-322: Syntax error, statement will be ignored.
It appears sas is attempting to convert the date into a character. I have no idea why
You either want to store the date value in the macro variable BEGDATE as the numeric representation instead of DATE9 format, or, what I would do is just tell SAS that you're resolving a date with the macro variable. e.g.
"&BegDate."d
You either want to store the date value in the macro variable BEGDATE as the numeric representation instead of DATE9 format, or, what I would do is just tell SAS that you're resolving a date with the macro variable. e.g.
"&BegDate."d
The other option is to change how you create the macro variable, but it won't look like a date anymore.
data _null_;
LMTE=intnx('Month',&pbd_date,-1,'b');
CALL SYMPUT('BegDate', LMTE);
run;
%put &BegDate;
Give this a try:
data _null_;
LMTE = intnx('Month',&pbd_date,-1,'b');
LMTE_cats_date9 = CATS('"', PUT(LMTE,date9.), '"', 'd');
CALL SYMPUT('BegDate', LMTE_cats_date9);
run;
%PUT &BegDate;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.