dates in if-then statements
From sasCommunity
sasCommunity Forum : sasCommunity - general site feedback : dates in if-then statementsBy Smg21778 on Sun Mar 09, 2008 11:23 pm
In my dataset, date of birth and date of death is in yyyymmdd format. I need to exclude observations who have a DOB after 1/1/1930 and a DOD between 1/1/1996 and 12/31/1999. How should I write the if-then statement? For the DOB exclusion criterion, I've tried:
if dob>19300101 then delete;
How should I write the if-then statement to delete the observations from my dataset?
Thanks,
smg21778
Private Message | Personal Page | Quote
By C1e0 on Wed Mar 19, 2008 5:38 pm
Smg21778 said:
In my dataset, date of birth and date of death is in yyyymmdd format. I need to exclude observations who have a DOB after 1/1/1930 and a DOD between 1/1/1996 and 12/31/1999. How should I write the if-then statement? For the DOB exclusion criterion, I've tried:
if dob>19300101 then delete;
How should I write the if-then statement to delete the observations from my dataset?
Thanks,
smg21778(1) change your date to a SAS date (no of days since January 1, 1960)
If your date is numeric, develop some mathematical equation to pull apart year/month/day... or convert to character: newdate = trim(left(put(olddate,best.)));
Then change back to a numeric SAS date using the handy v9 format anydtdt.
Once you have a SAS date, you may move forward to your "exclusion" criteria.
(2) "if dob>19300101 then delete;"
When using SAS dates, this statement should be written as:
if dob>'01JAN30'd and '01JAN96'd <= dod <= '31DEC1999'd then delete;
Private Message | Personal Page | Quote
By Pzagst on Wed Apr 02, 2008 10:38 am
in the column headings it will give you an option of the date set-up format. Copy the variable info to a new name data new; set old; datenew=date; run;
then in your datenew column you have the ability to change the format by right clicking on the column-> column attributes -> format. (i like to create an new column so you still have the old and your not changing any original data)
Hopefully that will work for you
Private Message | Personal Page | Quote
