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

Hello:

 

I would like to exclude the year 2009 in the variable 'DOB'.   DOB is the format of ''mmddyy10.''

Please advice how to approach it.  Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

The YEAR() function uses parenthesis, and there are no quotes around numbers, and of course the rest of your SAS code has to be correct syntax as well.

 

data want; 
set have;
if year(DOB) ne 2009; 
run;

But there's no real need to create a separate data set to do any analysis

 

proc means data=have(where=(year(dob) ne 2009));
...
run;

  

--
Paige Miller

View solution in original post

8 REPLIES 8
Reeza
Super User
You use YEAR() to get the YEAR() from a data component and then use the standard ne or eq or comparison desired. This assumes your variable is type=numeric and format is mmddyy10. If the type is character this does not apply.


ybz12003
Rhodochrosite | Level 12

So, it should be

 

 data want; set have; DOB ne year'2009'; run;

Reeza
Super User
No, but I'm assuming you tried that and it didn't work already with errors in the log.

YEAR() is function, the parameter would be a date variable that would return the date and then you would check if that value is not 2009.
Reeza
Super User
I'm going to assume you're just having a bad day, because this is pretty basic and you should be able to do this IMO, from what you post on here.
This would remove all records where the year of the date of birth is 2009.


if year(dob) ne 2009;
PaigeMiller
Diamond | Level 26

The YEAR() function uses parenthesis, and there are no quotes around numbers, and of course the rest of your SAS code has to be correct syntax as well.

 

data want; 
set have;
if year(DOB) ne 2009; 
run;

But there's no real need to create a separate data set to do any analysis

 

proc means data=have(where=(year(dob) ne 2009));
...
run;

  

--
Paige Miller
BrahmanandaRao
Lapis Lazuli | Level 10
data dsn;
input dob;
cards;
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
;
run;
data want; 
set dsn;
if dob eq 2009 then delete  ; 
run;
PaigeMiller
Diamond | Level 26

@BrahmanandaRao wrote:
data dsn;
input dob;
cards;
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
;
run;
data want; 
set dsn;
if dob eq 2009 then delete  ; 
run;

Or even shorter

 

data want;
input dob;
if dob ne 2009 then output;
cards;
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
;
run;

 

--
Paige Miller
ybz12003
Rhodochrosite | Level 12

Thank you so much, PaigeMiller!

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
  • 8 replies
  • 1526 views
  • 5 likes
  • 4 in conversation