0
votes

I want to create a SQL procedure on SAS with a where condition based on a date field. For example i need to count all the students born after 1 Jan 2002 The code is something like this:

PROC SQL;
SELECT COUNT(*) 
FROM students t
WHERE t.birth_date > '2002-01-01'

Looking at other stackOverflow topic I found that the solution is to use the input() function, but is not clear for me how to deal with different formats.

In this example the format of the birth_date field is: 01JUL2017:00:00:00

1

1 Answers

1
votes

You'll need to use the datepart function to extract only the date and not the time from the birth_date field. Also, for SAS to recognize a date, you need to add d to the end of the date string.

PROC SQL;
SELECT COUNT(*) 
FROM students t
WHERE datepart(t.birth_date) > '1JAN2002'd;
quit;