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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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