BookmarkSubscribeRSS Feed
luvscandy27
Quartz | Level 8

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;
2 REPLIES 2
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1665 views
  • 0 likes
  • 3 in conversation