Hi,
I would like to filter out 'Stay_Date' before today. How could I change the following code in Data step?
Data Work.A;
Set Work.B;
Where Stay_Date LE 'sysdate'd;
Run;
It returns error: Invalid Date / Time. As 'Stay_Date' format is '2015-12-31'. But the following code is fine:
Data Work.A;
Set Work.B;
Where Stay_Date LE '25APR2017'd;
Run;
How could I use System date instead of a particular one? Thank you!
@Crubal wrote:
It returns error: Invalid Date / Time. As 'Stay_Date' format is '2015-12-31'
It seems you are confusing a few issues here. Stay_Date (without the quotes) is 2015-12-31 without the quotes, and this is a formatted date value, it is not a character string (which is what the quotes would indicate). Thus you need to compare Stay_Date to a SAS date value, for example:
where stay_date le today();
No need for macro variables, or double-quotes to all the macro variable to be resolved.
A couple of small changes:
Where Stay_Date LE "&sysdate9"d;
It's important to use double quotes, so that the macro variable can resolve.
@Crubal wrote:
It returns error: Invalid Date / Time. As 'Stay_Date' format is '2015-12-31'
It seems you are confusing a few issues here. Stay_Date (without the quotes) is 2015-12-31 without the quotes, and this is a formatted date value, it is not a character string (which is what the quotes would indicate). Thus you need to compare Stay_Date to a SAS date value, for example:
where stay_date le today();
No need for macro variables, or double-quotes to all the macro variable to be resolved.
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.