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)

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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