BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Irenelee
Quartz | Level 8
May I know why Invalid date? thx a lot!
 
data FILTER;
set CRSP1;
where DATE between '1926-01-01'd and '1962-12-31'd;
ERROR: Invalid date/time/datetime constant '1926-01-01'd.
ERROR: Invalid date/time/datetime constant '1962-12-31'd.
ERROR: Syntax error while parsing WHERE clause.
擷取.JPG




DM'LOG; CLEAR; OUT; CLEAR; ODSRESULTS; CLEAR;';
%LET FOLDER=%STR(C:\USERS\SC\DESKTOP\HIGH);
LIBNAME HIGH "&FOLDER";
 
DATA CRSP;
SET HIGH.CRSP;
RUN;
 
DATA CRSP1;
SET  CRSP;
PRC=ABS(PRC);
IF SHRCD^=10 AND SHRCD^=11 THEN DELETE;
IF EXCHCD^=1 AND EXCHCD^=2 AND EXCHCD^=3 AND EXCHCD^=31 AND EXCHCD^=32 AND EXCHCD^=33 THEN DELETE;
 
KEEP PERMNO DATE PRC;
RUN;
 
PROC SORT DATA= CRSP1;
BY PERMNO DATE;
RUN;
 
data FILTER;
    set CRSP1;
    where DATE between '1926-01-01'd and '1962-12-31'd;
run;
 
proc summary data=FILTER noprint;
    by PERMNO;
    output out=historical_prices(drop=_:) 
           max(HIGH) = OHH
           min(LOW) = OLL;
run;
 
data final_data;
    merge FILTER historical_prices (keep=PERMNO OHH OLL);
    by PERMNO;
    where DATE = '1962-12-31'd;
run;
 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

SAS date literals are of the format 'DDmonYYYY'd.  Try:

where date between '01Jan1926'd and '31Dec1962'd ;

View solution in original post

1 REPLY 1
Quentin
Super User

SAS date literals are of the format 'DDmonYYYY'd.  Try:

where date between '01Jan1926'd and '31Dec1962'd ;

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
  • 1 reply
  • 926 views
  • 0 likes
  • 2 in conversation