BookmarkSubscribeRSS Feed
ybz12003
Rhodochrosite | Level 12

Hello, 

I found an error message when I ran a macro.  Please see the details below.  I won't be able to list the entire messages below.  There are a thousand lines.

%let bdate=2022_12_12;

proc sql;
create table cov&rr as
select site, date, id, ageyears, agemonths, 
       source, &regprodate1 
from CoV
where 
      (&regprodate1>"&bdate."d and &regprodate1 ^= '08aug8888'd) 
order by site,id;
ERROR: Invalid date/time/datetime constant "2022_12_12"d.
(covprovdt2>"2022_12_12"d and covprovdt2 ^= '08aug8888'd)

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):

I think the date format could not be recognized by SAS.  Do I have to create a new specific one shown below?

%let bdate1=12DEC2022;

The old one, 'bdate', needs to be used somewhere else.  Could I keep the old one, 'bdate', and make some modifications in the where command? Just curious.

 

4 REPLIES 4
PaigeMiller
Diamond | Level 26
ERROR: Invalid date/time/datetime constant "2022_12_12"d.

Must be in the form "12DEC2022"d (and not in any other form of representing dates)

 

So you want: 

%let bdate=12DEC2022;

 

--
Paige Miller
Tom
Super User Tom
Super User

A date literal,  a quoted string followed by the letter d,  needs to use a string that the DATE informat can recognize as a date.

It you need to use the date in two different ways go ahead and make another macro variable that has the actual date.  Note that it does not have to be formatted in a way that a human would understand it.

%let bdate=2022_12_12;
%let bdate_actual = %sysfunc(inputn(&bdate,yymmdd10.));

proc sql;
create table cov&rr as
select site, date, id, ageyears
    , agemonths
    , source, &regprodate1 
from CoV
where 
      (&regprodate1>&bdate_actual and &regprodate1 ^= '08aug8888'd) 
order by site,id
;

 

ybz12003
Rhodochrosite | Level 12
I don't want the computer system date. I would like to change bdate '2022_12_12' to bdate1 '12DEC2022' format. How?
Tom
Super User Tom
Super User

@ybz12003 wrote:
I don't want the computer system date. I would like to change bdate '2022_12_12' to bdate1 '12DEC2022' format. How?

Do you have an example of some code you need to use the macro to generate where you need to have that string?

The example you posted is comparing to a DATE variable. That will not work with a string like '12DEC2022'.  For that you need to use an actual date value.  So either the actual date value (such as 22991) or a date literal (such as "12DEC2022"d).

 

516  %put %sysevalf("12DEC2022"d);
22991

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1118 views
  • 0 likes
  • 3 in conversation