Hi,
i have write this macro:
%macro date_loop(start,end);
%let start=%sysfunc(inputn(&start,DATETIME16.));
%let end=%sysfunc(inputn(&end,DATETIME16.));
%let dif=%sysfunc(intck(HOUR,&start,&end));
%do i=0 %to &dif;
%let date=%sysfunc(intnx(HOUR,&start,&i,b),DATETIME16.);
%put &date;
data LDS.aA01_PROVA;
TM_INS_C = &date ;
FORMAT TM_INS_C DATETIME16.;
run;
%end;
%mend date_loop;
%date_loop(01JAN19:00:00:00,01JAN19:00:01:59);
I need to store the value of variabile &date in table LDS.aA01_PROVA, but i recived this error:
8986 %macro date_loop(start,end);
8987 %let start=%sysfunc(inputn(&start,DATETIME16.));
8988 %let end=%sysfunc(inputn(&end,DATETIME16.));
8989 %let dif=%sysfunc(intck(HOUR,&start,&end));
8990 %do i=0 %to &dif;
8991 %let date=%sysfunc(intnx(HOUR,&start,&i,b),DATETIME16.);
8992 %put &date;
8993
8994
8995 data LDS.aA01_PROVA;
8996 TM_INS_C = &date ;
8997 FORMAT TM_INS_C DATETIME16.;
8998 run;
8999
9000
9001
9002
9003 %end;
9004 %mend date_loop;
9005
9006 %date_loop(01JAN19:00:00:00,01JAN19:00:01:59);
01JAN19:00:00:00
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set LDS.AA01_PROVA may be incomplete. When this step was stopped there were 0
observations and 1 variables.
WARNING: Data set LDS.AA01_PROVA was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.11 seconds
cpu time 0.04 seconds
NOTE: Line generated by the macro variable "DATE".
1 01JAN19:00:00:00
-----
388
76
ERROR 388-185: Expecting an arithmetic operator.
ERROR 76-322: Syntax error, statement will be ignored.
What is my mistake ?
thank's much
!
To elaborate on what @PaigeMiller is saying and the impact it has, look at the results of the %PUT statement on line 8992. It generates:
01JAN19:00:00:00
Then look at how you use the macro variable later, on line 8996:
TM_INS_C = &date ;
That generates an erroneous SAS statement:
TM_INS_C = 01JAN19:00:00:00 ;
That's where you get the error message. One proper version of the statement would be:
TM_INS_C = "&date"dt ;
Or, as @PaigeMiller mentioned, you could just leave &DATE unformatted, holding the proper numeric value that could be assigned using:
TM_INS_C = &date ;
No need to format your macro variable as human readable dates. In fact, that is the cause of the error you got.
%macro date_loop(start,end);
%let dif=%sysfunc(intck(HOUR,"&start"dt,"&end"dt));
%do i=0 %to &dif;
%let date=%sysfunc(intnx(HOUR,&start,&i,b));
%put &=date;
data LDS.aA01_PROVA;
TM_INS_C = &date ;
FORMAT TM_INS_C DATETIME16.;
run;
%end;
%mend date_loop;
%date_loop(01JAN19:00:00:00,01JAN19:00:01:59)
To elaborate on what @PaigeMiller is saying and the impact it has, look at the results of the %PUT statement on line 8992. It generates:
01JAN19:00:00:00
Then look at how you use the macro variable later, on line 8996:
TM_INS_C = &date ;
That generates an erroneous SAS statement:
TM_INS_C = 01JAN19:00:00:00 ;
That's where you get the error message. One proper version of the statement would be:
TM_INS_C = "&date"dt ;
Or, as @PaigeMiller mentioned, you could just leave &DATE unformatted, holding the proper numeric value that could be assigned using:
TM_INS_C = &date ;
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.