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 ;
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

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 ;
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 456 views
  • 0 likes
  • 2 in conversation