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 ;
BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

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 ;
BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 320 views
  • 0 likes
  • 2 in conversation