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!
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!
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.