DATA Step, Macro, Functions and more

Unexplained date error using date macro

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 131
Accepted Solution

Unexplained date error using date macro

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


Accepted Solutions
Solution
‎12-08-2015 04:31 PM
Contributor
Posts: 55

Re: Unexplained date error using date macro

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

View solution in original post


All Replies
Solution
‎12-08-2015 04:31 PM
Contributor
Posts: 55

Re: Unexplained date error using date macro

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

Super User
Posts: 17,784

Re: Unexplained date error using date macro

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;

Contributor hbi
Contributor
Posts: 66

Re: Unexplained date error using date macro

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;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 290 views
  • 2 likes
  • 4 in conversation