• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 550
  • Last Modified:

filter condition

Hi There,
Trying to run below query getting error below dateformat is yymmdd8
16         proc sql;
17          create table myams as(
18            select * from aa.TMP
19             where date='2011-04-19');
ERROR: Expression using equals (=) has components that are of different data types.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
0
sam2929
Asked:
sam2929
1 Solution
 
bradanelsonCommented:
Try using this example:

proc sql;
         create table myams as(
           select * from aa.TMP
            where date='19APR2011'D);
quit;

0
 
d507201Commented:
As bradanelson pointed out above, you're comparing a date variable to a literal character string.  SAS stores date variables as numbers--the number of days before or after January 1, 1960.  You'll  often see dates referred to as 'date values'.    0 is 1/1/1960 and 18752 is 5/5/2011.

If you know the number of days then you can use a number in a comparison or assignment statement.  But it's easier to specify a date value as '19APR2011'D.   The trailing D (or d) tells SAS to convert the literal into a date value.  The format must always be 'ddmmmyyyy'd although a two-digit yy will work but be very careful with those nowadays.

There are lots of good SAS conference papers written about SAS and dates.  If you're going to be working with dates quite a bit then it will be very much worth your while to read some of them.  This is a great web site for user-written SAS documentation-- www.lexjansen.com
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now