BookmarkSubscribeRSS Feed
CRM_Ben
Calcite | Level 5

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 

8 REPLIES 8
novinosrin
Tourmaline | Level 20

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;

CRM_Ben
Calcite | Level 5
Thanks, i'll try this
Reeza
Super User

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.

 

CRM_Ben
Calcite | Level 5

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 

ballardw
Super User

@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.

Patrick
Opal | Level 21

@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;
mkeintz
PROC Star

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.

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ShiroAmada
Lapis Lazuli | Level 10

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3164 views
  • 0 likes
  • 7 in conversation