BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cneed
Obsidian | Level 7

Hello! I am new to SAS and cant seem to get past this error after WHERE birthdate > 01/01/2001. When I run this I keep getting an error that says "ERROR: Expression using greater than (>) has components that are of different data types". They all have matching data types of:

 

birthdateNum8MMDDYY10. birthdate
genderChar1$1.$1.gender
schoolIDNum8BEST. schoolID
schoolnameChar9$9.$9.schoolname
studentIDNum8BEST. studentID

 

 

Code:

 

/*Question 1*/
PROC SQL;
CREATE TABLE Data.master_WithSchoolInfo AS
SELECT A.studentID, A.Birthdate, A.Gender, B.SchoolID, B.SchoolName
FROM Data.master A LEFT JOIN Data.school B
ON A.SchoolID = B.SchoolID;
RUN;

PROC CONTENTS DATA = Data.master_WithSchoolInfo;
RUN;


/*Question 2*/
PROC SQL;
CREATE TABLE Data.master_After2001 AS
SELECT *
FROM Data.master_WithSchoolInfo
WHERE Birthdate > '01/01/2001';
RUN;

PROC CONTENTS DATA = Data.master_WithSchoolAfter2001;
RUN;

 

Can someone help me figure this out?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Birthdate is likely a numerical variable containing a SAS date value (count of days since 01 Jan 1960). Normally a SAS format gets applied to such variables so when you look at it (print it) then the value becomes human readable. 

Execute below. This will tell you of what type the variables are and what formats they use (if any).

proc contents data=Data.master; run; 

If above assumption is correct (birthdate being of type numeric containing a SAS date value) then you need to formulate the fixed date in your where clause also in a way which instructs SAS that this is a SAS date value. Below should work.

WHERE Birthdate > '01JAN2001'd 

 

View solution in original post

3 REPLIES 3
SASKiwi
PROC Star

Birthdate is a numeric variable but you are comparing it to a character string - '01/01/2001'. Changing your WHERE clause to use a date constant like so should fix your error:

WHERE Birthdate > '01Dec2001'd

 

Patrick
Opal | Level 21

Birthdate is likely a numerical variable containing a SAS date value (count of days since 01 Jan 1960). Normally a SAS format gets applied to such variables so when you look at it (print it) then the value becomes human readable. 

Execute below. This will tell you of what type the variables are and what formats they use (if any).

proc contents data=Data.master; run; 

If above assumption is correct (birthdate being of type numeric containing a SAS date value) then you need to formulate the fixed date in your where clause also in a way which instructs SAS that this is a SAS date value. Below should work.

WHERE Birthdate > '01JAN2001'd 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3450 views
  • 0 likes
  • 3 in conversation