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.
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;
So, it should be
data want; set have; DOB ne year'2009'; run;
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;
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;
@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;
Thank you so much, PaigeMiller!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.