BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aleixo
Quartz | Level 8

Hi,

 

I had this ERROR about dates. I tried with fix dates like 01JAN2012 and 07FEB2018 and works fine. I don't know why SAS doesn't like calculated variables.

 

34         
35         GOPTIONS ACCESSIBLE;
36         %let date=2012-01-01;
37         %let date_d9=%sysfunc(inputn(&date, yymmdd10.), date9.);
38         %put &date_d9.;
01JAN2012
39         
40         %let tdate = %sysfunc(today(),date9.);
41         %put &tdate.;
07FEB2018
42         
43         PROC SQL;
44         CREATE TABLE WORK.TEST AS
45         SELECT t1.'Instalação'n,
46                   t1.Painel,
47                   t1.'Último Disparo'n
48         FROM WORK.LISTADISJUNTORESRND t1
49         WHERE t1.'Último Disparo'n BETWEEN 'date_d9.'d AND 'tdate.'d;
ERROR: Invalid date/time/datetime constant 'date_d9.'d.
ERROR: Invalid date/time/datetime constant 'tdate.'d.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
50         quit;
NOTE: The SAS System stopped processing this step because of errors.

Regards,

Aleixo

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

You need to refer to your macro variables properly.  That means adding &, and using double quotes instead of single quotes:

 

 

WHERE t1.'Último Disparo'n BETWEEN "&date_d9."d AND "&tdate."d;

View solution in original post

4 REPLIES 4
Astounding
PROC Star

You need to refer to your macro variables properly.  That means adding &, and using double quotes instead of single quotes:

 

 

WHERE t1.'Último Disparo'n BETWEEN "&date_d9."d AND "&tdate."d;

Aleixo
Quartz | Level 8

Thanks a lot. Yes it is true. I try with & but i never put characters "" .

Reeza
Super User

Two errors:

 

1. No & (ampersand) before the macro variables

2. Macro variables only resolve in double quotes

 

Once you make those changes it should work.

Aleixo
Quartz | Level 8

Thank you.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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