11-27-2013 10:09 PM
Hi i have a simple question, but i am unable to solve it
i just want to automize one of my queries and i need to change WHERE clause to System date -1 day. Is it possible in EG 5.1 using SYSDATE-1 instead of proper date
17 CREATE TABLE WORK.SAMPLE_QUERY AS
18 SELECT t1.ID_NO,
20 FROM O_C_OPR.DATABASEONE t1
21 WHERE t1.KREDI_TARIHI = '1Nov2013:3:0:0'dt;
Thank you E
11-27-2013 11:25 PM
All of Art's questions plus: Does this query run against a table in a database?
You probably wouldn't use &sysdate as this is the date when you started your SAS EG session. I would assume the solution will be something using datetime() together with intnx().
If the source table is in a database then you could create a datetime string so that the query gets pushed to the data base. Something like: "&datestring"d
Assuming that you want to run the job overnight there is always midnight to be considered. So can you tell us between which times the job could possibly run and then which datetime value you want to pass to the where clause?
11-28-2013 04:39 AM
Something like below should do the job. It's using the SAS datetime() function to retrieve the current system datetime and it's using intnx() to shift this datetime value to the beginning of the previous day.
I'm using %sysfunc() to create a string containing the required datetime value so I then can used 'dt' to convert it to a datetime value. This way the SAS Access engine "knows" that it is dealing with a datetime value and will convert it to an appropriate data base SQL expression.
There might be easier way of doing this - but below is what I'm normally doing and where I know that it will work.
I've also added "options sastrace=",,,d" sastraceloc=saslog nostsuffix;"
Once you run the code against a data base these options will show you in the log what part of the SQL has been sent to the data base for processing. If the SAS Access engine wasn't able to translate everything then you might consider to re-formulate your SQL or to use explicit pass-through SQL.
format dt dt_string_to_dt datetime21.;
do i=-5 to 5;
options sastrace=",,,d" sastraceloc=saslog nostsuffix;
create table want as