BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
VALLY
Fluorite | Level 6

good day

am running the below code , however it returns the error listed above 

 PROC SQL;
 CREATE TABLE VIEW AS 
 SELECT * 
 FROM have
 WHERE DATE_OPENED => 2023-04-10 ;
 QUIT;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

The data is specified incorrectly. That format is ambiguous as it could be a subtraction or date. 

Date constants in SAS are specified using 'DDMMMYY'd format, assuming this is a SAS date that's numeric. If date_opened is a character variable, you need to include it in quotes and due to numeric order it will still return the correct value. 

DATE_OPENED is numeric (SAS date format)

 PROC SQL;
 CREATE TABLE VIEW AS 
 SELECT * 
 FROM have
 WHERE DATE_OPENED => '10Apr2023'd ;
 QUIT;

DATE_OPENED is character

 PROC SQL;
 CREATE TABLE VIEW AS 
 SELECT * 
 FROM have
 WHERE DATE_OPENED => '2023-04-10' ;
 QUIT;

@VALLY wrote:

good day

am running the below code , however it returns the error listed above 

 PROC SQL;
 CREATE TABLE VIEW AS 
 SELECT * 
 FROM have
 WHERE DATE_OPENED => 2023-04-10 ;
 QUIT;

 

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

You need to share the LOG to clarify what error you are getting.

 

476  PROC SQL;
477   CREATE TABLE VIEW AS
478   SELECT *
479   FROM have
480   WHERE DATE_OPENED => 2023-04-10 ;
                         -
                         22
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
              a missing value, BTRIM, INPUT, PUT, SUBSTRING, USER.

481   QUIT;

Looks like SQL does not like the use of = followed by >.  Did you mean "greater than or equal to"?  If so then you need to use >= or better still use the GE pneumonic instead.

 

 

The code has other issues also. 

  • It is not a good idea to name a dataset with the name VIEW.  That is just confusing. 
  • from the variable name I suspect that you need to have a DATE value after the GE operator. Currently you have a complex way of specifying the number 2,009 which is the date '02JUL1965'd.  Although it is possible that the variable actual has DATETIME values instead, in which case the number 2,009 is the datetime value '01JAN1960:00:33:29'dt.
498  data _null_;
499    x=2023-04-10 ;
500    put x= comma. x=date9. x=datetime19.;
501  run;

x=2,009 x=02JUL1965 x=01JAN1960:00:33:29
PaigeMiller
Diamond | Level 26

In addition to the => error mentioned above, you also have this error:

 

2023-04-10

 

is how you do subtraction in SAS. SAS thinks you mean 2023 minus 4 minus 10. It is not a date (normally). Maybe you mean

 

'04OCT2023'd

 

which SAS will always recognize as the date October 4, 2023; or maybe you mean something else.

--
Paige Miller
Reeza
Super User

The data is specified incorrectly. That format is ambiguous as it could be a subtraction or date. 

Date constants in SAS are specified using 'DDMMMYY'd format, assuming this is a SAS date that's numeric. If date_opened is a character variable, you need to include it in quotes and due to numeric order it will still return the correct value. 

DATE_OPENED is numeric (SAS date format)

 PROC SQL;
 CREATE TABLE VIEW AS 
 SELECT * 
 FROM have
 WHERE DATE_OPENED => '10Apr2023'd ;
 QUIT;

DATE_OPENED is character

 PROC SQL;
 CREATE TABLE VIEW AS 
 SELECT * 
 FROM have
 WHERE DATE_OPENED => '2023-04-10' ;
 QUIT;

@VALLY wrote:

good day

am running the below code , however it returns the error listed above 

 PROC SQL;
 CREATE TABLE VIEW AS 
 SELECT * 
 FROM have
 WHERE DATE_OPENED => 2023-04-10 ;
 QUIT;

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 3 replies
  • 343 views
  • 0 likes
  • 4 in conversation