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

Is there a way to insert a prompt in your where statement to filter for the date. Below is the code the way I tried it, but it doesn't work.

 

proc print data=SOMEDATA;

where datepart(error_dt) > '&date';

run;

 

Where error_dt is a date variable.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@RubenPloeg wrote:

I know that inserting a date will work, but it doesn't allow the user to choose a date from a prompt. That was what i was referring to. The error I get when trying to use a prompt is that the where clause operator requires compatible variables. Thus, I'm pretty sure this way I will not be able to work with a prompt for the date. My question was, is there another way?


I don't use prompts but I think it will set the macro variable to a string that looks like the date value when printed with the DATE9 format.  So you could use it to make a date literal in your code.  If the macro variable created is named DATE then you want to use 

"&date"d

in your code.  Note that double quotes instead of single is needed to allow the macro process to convert &date into the value of DATE.  The letter D is need to let SAS know that you want it to treat this as a date value and not a string.

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

This works

 

proc print data=somedata;
    where error_dt > '01JAN2020'd;
run;

For future reference, saying "but it doesn't work" and providing no further details usually is not a good thing to do ... you need to provide details (the LOG and/or incorrect outputs) about what happened so we can all see what didn't work.

--
Paige Miller
RubenPloeg
Calcite | Level 5

I know that inserting a date will work, but it doesn't allow the user to choose a date from a prompt. That was what i was referring to. The error I get when trying to use a prompt is that the where clause operator requires compatible variables. Thus, I'm pretty sure this way I will not be able to work with a prompt for the date. My question was, is there another way?

PaigeMiller
Diamond | Level 26

As I don't use Enterprise Guide, I can't specifically answer about a prompt that the user has to fill in.

--
Paige Miller
Tom
Super User Tom
Super User

@RubenPloeg wrote:

I know that inserting a date will work, but it doesn't allow the user to choose a date from a prompt. That was what i was referring to. The error I get when trying to use a prompt is that the where clause operator requires compatible variables. Thus, I'm pretty sure this way I will not be able to work with a prompt for the date. My question was, is there another way?


I don't use prompts but I think it will set the macro variable to a string that looks like the date value when printed with the DATE9 format.  So you could use it to make a date literal in your code.  If the macro variable created is named DATE then you want to use 

"&date"d

in your code.  Note that double quotes instead of single is needed to allow the macro process to convert &date into the value of DATE.  The letter D is need to let SAS know that you want it to treat this as a date value and not a string.

RubenPloeg
Calcite | Level 5

the double qutes helped, thanks!

Kurt_Bremser
Super User
  • to resolve a macro variable in a quoted string, you must use double quotes
  • if a variable is already a date (and not a datetime), do NOT use the DATEPART function
  • to convert the string from the prompt to a date value, you must add a trailing d immediately following the closing double quote ("&date"d)

SAS Innovate 2025: Call for Content

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!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 2126 views
  • 0 likes
  • 4 in conversation