Hello all, I am working with the code below and I keep getting the error. ERROR: Invalid date/time/datetime constant "stdft."d. I have checked my
formats and they are all the same and I just can't seem to figure out what is causing the error?
data dates;
infile datalines delimiter = ',';
input ID $ DATE:anydtdte11. COND STDT:anydtdte11. ENDT:anydtdte11. ;
format date stdt endt mmddyy10.;
datalines;
1, 05/03/2018, ., 05/03/2017, 05/03/2018
1, 05/02/2018, ., 05/02/2017, 05/03/2018
2, 04/26/2018, 1, 04/26/2017, 04/27/2018
2, 04/18/2018, 1, 04/18/2017, 04/18/2018
2, 04/10/2018, 1, 04/10/2017, 04/10/2018
;
run;
proc sql;
create table want as
select distinct *, stdt as STDFT format date9., stdt as ENDTFT format date9.
from dates
where cond=1 and date between "stdft."d and "endtft."d;
quit;
What it says. The string
stdft.
is not a valid date in DATE9. format (which is needed for a date literal).
Your variables STDT and ENDT are already valid SAS dates. You don't need to put quotes around them and add D as in "stdft."d. You can just use STDT and ENDT without modification.
proc sql;
create table want as
select distinct *
from dates
where cond=1 and date >= stdt and date <= endt;
quit;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: