Removing Year from a date

Reply
New Contributor
Posts: 3

Removing Year from a date

Hi, 

 

I need to create a campaign, using CI, based on a customers date of birth. To do so i need to remove the year, as this is irrelvant, and focus purely on the day and month. 

 

Is there are function available to do this? 

 

Thanks

Ben 

PROC Star
Posts: 1,547

Re: Removing Year from a date

[ Edited ]

You could extract day and month using day and month functions. Do you have a sample input and wanted output for the community to know your requirement

 

You could also use a format like this:

 

data w;
date=today();
new_date=put(date,date5.);
format date date5.;
run;

proc contents;run;

New Contributor
Posts: 3

Re: Removing Year from a date

Posted in reply to novinosrin
Thanks, i'll try this
Super User
Posts: 23,224

Re: Removing Year from a date

90% of the time SAS dates are more efficient, this may be one that it's not.

 

I don't know how you're filtering/grouping but does applying a different format help at all?

 

This would filter all people born on October 5th.

 

where day(birth_date)=5 and month(birth_date)=10;

You can use the ddmmyy4. format to create a variable that's just day and month and then would filter as:

 

where put(date, mmddyy4.) = '1005';

If you apply the MMDDYY4. format the summary tables should be by day/month as well.

 

New Contributor
Posts: 3

Re: Removing Year from a date

Hi, 

 

The format is curently DATE9. but i'm trying to create a calculated item with, for example, 01JAN. 

 

This will allow me to select all birthdays in on a certain date without having to condsider all the possible years they could have been born in. 

 

Thanks

Ben 

Super User
Posts: 13,283

Re: Removing Year from a date


CRM_Ben wrote:

Hi, 

 

The format is curently DATE9. but i'm trying to create a calculated item with, for example, 01JAN. 

 

This will allow me to select all birthdays in on a certain date without having to condsider all the possible years they could have been born in. 

 

Thanks

Ben 


if month(date)=1 and day(date)=1 then do <whatever>;

would find specific month and day

 

If you have other variables with the month/day numbers you could use those instead of the 1's I used since you mentioned 01Jan.

Respected Advisor
Posts: 4,665

Re: Removing Year from a date

[ Edited ]

@CRM_Ben

Using an approach as in code below should allow you to get what you're after. This approach will also deal nicely with leap years.

data have;
  format DoB date9.;
  do DoB='01Jan1995'd to '31Dec2000'd;
    output;
  end;
run;


/* select all DoB in the next 3 to 9 days based on date of &start_dt */
%let start_dt=28Feb2016;
data want;
  format Start_Dt DoB _Start_Dt_aligned date9.;
  set have;
  retain Start_Dt "&start_dt"d;

  _Start_Dt_aligned=intnx('year',Start_Dt,year(DoB)-year(Start_Dt),'s');

  if (3 <= (DoB - _Start_Dt_aligned) <= 9) then output;
run;
Trusted Advisor
Posts: 1,309

Re: Removing Year from a date

If you're taking only a customer's month and day of birth in order to trigger some treatment of customer data or initiating communication with the customer, you may need to aggregate Feb 29 birth dates with either Mar 1 or Feb 28.  Otherwise 3 years out of 4 you might overlook persons born on leap day.

 

Frequent Contributor
Posts: 113

Re: Removing Year from a date

Try this.....

 

data HAVE;
format dates date9.;
  do y=2000 to 2010;
    do m=1 to 12;
      do dates=mdy(m,1,y) to intnx('month',mdy(m,1,y),0,'e');
          output;
        end;
      end;
  end;
run;


%macro SeparateByBirthMonth;
%do i=1 %to 12;
  %let var&i=&i.;
%end;

  data %do i=1 %to 12;
      want_&i.
       %end;;
    set HAVE;
        %do i=1 %to 12;
              %if %eval(&i=1) %then %do;
                if month(dates)=&i. then output want_&i.;
              %end;
                    %else %if %eval(&i>1) %then %do;
                      else if month(dates)=&i. then output want_&i.;
                    %end;
        %end;
  run;

%mend;
options macrogen;
%SeparateByBirthMonth;

 

Hope this helps.

Ask a Question
Discussion stats
  • 8 replies
  • 202 views
  • 0 likes
  • 7 in conversation