date format issues

Reply
New Contributor
Posts: 2

date format issues

Hi,

I am trying to automate my code.

I am getting errors. The same code works fine if called like this: %check_elig(method=eom,start='01jan2011'd, end='31may2011'd, state=nm);

22       

23         options fmtsearch=(auto WORK frmtdir library);

24         options mprint symbolgen mlogic pageno=1 nocenter;

25       

26         data _null_;

27         %let today=%sysfunc(today());

28         %let sdate= %str(%')%sysfunc(intnx(month,&today,-2,b),yymmdd10.)%str(%');

SYMBOLGEN:  Macro variable TODAY resolves to 19660

29         %let edate= %str(%')%sysfunc(intnx(month,&today,-1,e),yymmdd10.)%str(%');

SYMBOLGEN:  Macro variable TODAY resolves to 19660

30          call symput("bullet",'95'x);

31          call symput("tm",'AE'x);

32          call symput("copyright",'A9'x);

33         run;

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

    

34       

35       

36         %macro check_elig(method=,start=, end=, state=);

37       

38         data _null_;

39       

40          start=mdy(substr("&start",7,2),substr("&start",10,2),substr("&start",2,4));

2 The SAS System                                                                                     15:31 Tuesday, October 29, 2013

41          end=mdy(substr("&end",7,2),substr("&end",10,2),substr("&end",2,4));

42          call symput('months',intck('month', &start, &end));

43       

44       

45         run;

46       

47         data _null_;

48             %do i=0 %to &months;

49                 call symput("start_&i","'"||put(intnx('month', &start, &i, 'B'),yymmdd10.)||"'");

50                 call symput("end_&i","'"||put(intnx('month', &start, &i, 'E'),yymmdd10.)||"'");

51                 call symput("nondrug_&i","nondrug_"||strip(year(intnx('month', &start, &i, 'B')))||strip(put(month(intnx('month',

51       !  &start, &i, 'B')),z2.)));

52                 call symput("drug_&i","drug_"||strip(year(intnx('month', &start, &i, 'B')))||strip(put(month(intnx('month',

52       ! &start, &i, 'B')),z2.)));

53             %end;

54         run;

55       

56       

57         %mend check_elig;

58       

59         /*

60         %check_elig(method=eom,start='01jan2011'd, end='31may2011'd, state=nm);

61         */

62         %check_elig(method=eom,start=%unquote(&sdate), end=%unquote(&edate), state=nm);

MLOGIC(CHECK_ELIG):  Beginning execution.

SYMBOLGEN:  Macro variable SDATE resolves to '2013-08-01'

SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.

SYMBOLGEN:  Macro variable EDATE resolves to '2013-09-30'

SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.

MLOGIC(CHECK_ELIG):  Parameter METHOD has value eom

MLOGIC(CHECK_ELIG):  Parameter START has value '2013-08-01'

MLOGIC(CHECK_ELIG):  Parameter END has value '2013-09-30'

MLOGIC(CHECK_ELIG):  Parameter STATE has value nm

MPRINT(CHECK_ELIG):   data _null_;

SYMBOLGEN:  Macro variable START resolves to '2013-08-01'

SYMBOLGEN:  Macro variable START resolves to '2013-08-01'

SYMBOLGEN:  Macro variable START resolves to '2013-08-01'

MPRINT(CHECK_ELIG):   start=mdy(substr("'2013-08-01'",7,2),substr("'2013-08-01'",10,2),substr("'2013-08-01'",2,4));

SYMBOLGEN:  Macro variable END resolves to '2013-09-30'

SYMBOLGEN:  Macro variable END resolves to '2013-09-30'

SYMBOLGEN:  Macro variable END resolves to '2013-09-30'

MPRINT(CHECK_ELIG):   end=mdy(substr("'2013-09-30'",7,2),substr("'2013-09-30'",10,2),substr("'2013-09-30'",2,4));

SYMBOLGEN:  Macro variable START resolves to '2013-08-01'

SYMBOLGEN:  Macro variable END resolves to '2013-09-30'

MPRINT(CHECK_ELIG):   call symput('months',intck('month', '2013-08-01', '2013-09-30'));

MPRINT(CHECK_ELIG):   run;

NOTE: Character values have been converted to numeric values at the places given by: (Line)Smiley SadColumn).

      62:29    62:50    62:72    62:104   62:123   62:143   62:2     62:2   

NOTE: Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn).

      62:186 

NOTE: Invalid numeric data, '2013-08-01' , at line 62 column 2.

NOTE: Invalid numeric data, '2013-09-30' , at line 62 column 2.

start=19571 end=19631 _ERROR_=1 _N_=1

NOTE: Missing values were generated as a result of performing an operation on missing values.

      Each place is given by: (Number of times) at (Line)Smiley SadColumn).

      1 at 62:186 

NOTE: DATA statement used (Total process time):

3 The SAS System                                                                                     15:31 Tuesday, October 29, 2013

      real time           0.00 seconds

      cpu time            0.00 seconds

    

MPRINT(CHECK_ELIG):   data _null_;

SYMBOLGEN:  Macro variable MONTHS resolves to            .

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

       &months

ERROR: The %TO value of the %DO I loop is invalid.

ERROR: The macro CHECK_ELIG will stop executing.

MLOGIC(CHECK_ELIG):  Ending execution.

63       

64         GOPTIONS NOACCESSIBLE;

65         %LET _CLIENTTASKLABEL=;

66         %LET _CLIENTPROJECTPATH=;

67         %LET _CLIENTPROJECTNAME=;

68         %LET _SASPROGRAMFILE=;

69       

70         ;*';*";*/;quit;run;

                     ____

                     180

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: The SAS System stopped processing this step because of errors.

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

    

71         ODS _ALL_ CLOSE;

72       

73       

74         QUIT; RUN;

75      

Super User
Posts: 19,851

Re: date format issues

Posted in reply to saslearner_2013

This is your third post with the same question.

If you know a date9. format works, why not using that format instead of yymmdd10? I don't think that will be the full solution, you'll probably have to find a way to add the quote and D after as well.

Or just using straight dates without any format, ie 19660.

Super User
Super User
Posts: 7,074

Re: date format issues

Posted in reply to saslearner_2013

In SAS a date literal is of the form "ddMMMyyyy"d .  You cannot use any other format for a date LITERAL.

If you want to pass into you macro a date string is some other form then add logic to your macro to convert that string into an actual date value.  Either a date literal in a valid format or just the number of days since 1/1/1960.

%macro mymac(sdate=,edate=);

%let sdate=%sysfunc(inputn(&sdate,anydtdte12.),date9.);

%let edate=%sysfunc(inputn(&edate,anydtdte12.),date9.);

%put sdate=&sdate;

%put edate=&edate;

data _null_;

  do i="&sdate"d to "&edate"d;

     put i= i date9. +1 i yymmdd10. ;

end;

run;

%mend mymac;

%mymac(sdate=2013-10-30,edate=2013-11-02);

sdate=30OCT2013

edate=02NOV2013

i=19661 30OCT2013 2013-10-30

i=19662 31OCT2013 2013-10-31

i=19663 01NOV2013 2013-11-01

i=19664 02NOV2013 2013-11-02

Ask a Question
Discussion stats
  • 2 replies
  • 722 views
  • 0 likes
  • 3 in conversation