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
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;
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.
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
@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.
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;
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: