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.
@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.
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.
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?
As I don't use Enterprise Guide, I can't specifically answer about a prompt that the user has to fill in.
@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.
the double qutes helped, thanks!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.