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

I've been through the forums and can't quite find anything that fits what I'm having an issue with, so apologies if this is a repost.

 

I need to push a date into a global variable so I can call it within my program. Currently I get the date from:

 

PROC SQL noprint;
SELECT INTNX('MONTH',MDY(quarter*3,1,year),0,'E') format=date9. INTO :livd
FROM HPIindex
WHERE year = (SELECT MAX(year) FROM HPIindex)
HAVING quarter = MAX(quarter);
RUN;

 

When I try to apply this as a date it is coming out as a character string so throwing an error:

 

DATA dates;
SET date_table;
WHERE DATEPART(the_date) = &livd;
RUN;

 

NOTE: Line generated by the macro variable "LIVD".
28 30JUN2018
_______
22
76
ERROR: Syntax error while parsing WHERE clause.
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.

 

Is there any way to create the &livd variable as a date instead of a string? So basically producing '30JUN2018'd instead of 30JUN2018?

 

Thanks, any help appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Do not use a format for your macro variable:

SELECT INTNX('MONTH',MDY(quarter*3,1,year),0,'E') INTO :livd

or use your macro variable as a date literal if it is formatted:

WHERE DATEPART(the_date) = "&livd"d;

Personally, I prefer the first option, as it makes writing subsequent code easier.

 

PS This is covered in Maxim 28.

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

Do not use a format for your macro variable:

SELECT INTNX('MONTH',MDY(quarter*3,1,year),0,'E') INTO :livd

or use your macro variable as a date literal if it is formatted:

WHERE DATEPART(the_date) = "&livd"d;

Personally, I prefer the first option, as it makes writing subsequent code easier.

 

PS This is covered in Maxim 28.

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
  • 1 reply
  • 1332 views
  • 0 likes
  • 2 in conversation