BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
appleorange
Obsidian | Level 7

This is very bizarre and I can't figure out for the life of me why but I have some data with birth dates and eligibility dates.  The data is originally in a txt file and I am reading in the birth_date as mmddyy10.  The eligibility_month data is in numeric format and appears like this:

 

Birth_date     ID      Eligibility_Month

01/01/2016  0001   201511

01/01/2016  0001   201512

01/01/2016  0001   201601

01/01/2016  0001   201602

01/01/2016  0001   201603

01/01/2016  0001   201604

01/01/2016  0001   201605

 

I've tried reading in eligibility_month as yymmn6. and numeric, then converting it to yymmn6. using:

 

data mom_elig_2016_3;
set mom_eligibility_2016_2; yymm=input(put(eligible_month_yyyymm, 6.), yymmn6.);
format yymm yymmn6.;
informat yymm yymmn6.;
date_my=birth_date;
format date_my yymmn6.;
informat date_my yymmn6.;
run;

 

The idea is to check if the birth_date = an equivalent entry in the eligibility_month.  I reformatted birth_date into the same format.

 

For some reason, SAS recognizes SOME of the date_my and yymm as equivalent but not others.  

 

data aa1; set mom_elig_2016_3;
if date_my=yymm; run;

So for example, this is inaccurate because I see records where date_my = yymm clearly equals each other but isn't picked up.  I must be missing something to do with formatting but I can't figure out what it is.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
You never actually lose the day component it's still there in the data, just not displayed. So if the day of the month/years don't match then it won't match. Convert both to character or use INTNX() to set the birthdates to the beginning or end of the month as needed.

View solution in original post

4 REPLIES 4
singhsahab
Lapis Lazuli | Level 10
data have;
length Eligibility_Month 6.;
	input Birth_date  ddmmyy10. ID   Eligibility_Month ;
format birth_date ddmmyy10.;
datalines;
01/01/2016 0001 201511
01/01/2016 0001 201512
01/01/2016 0001 201601
01/01/2016 0001 201602
01/01/2016 0001 201603
11/11/2019 0002 201911
;
run;

data want;
set te;
o_mon=month(Birth_date);
o_yr=year(Birth_date);
if length(strip(put(o_mon,best.))) eq 1 then
birht_date_n=strip(strip(put(o_yr,best.))||'0'||strip(put(o_mon,best.)));
else birht_date_n=strip(strip(put(o_yr,best.))||strip(put(o_mon,best.)));
if input(birht_date_n,6.) eq Eligibility_Month then output;
drop o_mon o_yr birht_date_n;
run;
PaigeMiller
Diamond | Level 26

Formatting doesn't change the underlying value. Two dates can be formatted to look identical, but the underlying values are not equal, and so

 

if date_my=yymm;

would fail.

 

So the idea of formatting things to look the same won't help here.

 

The act of turning eligible_month_yyyymm to character and then back to numeric also seems unnecessary. If eligible_month is numeric string, you could turn it into an actual sas day via the INPUT command. If it is numeric, something like this would work:

 

yymm = mdy(mod(eligibility_month,100),1,floor(eligibility_month/100));

 

 

--
Paige Miller
Reeza
Super User
You never actually lose the day component it's still there in the data, just not displayed. So if the day of the month/years don't match then it won't match. Convert both to character or use INTNX() to set the birthdates to the beginning or end of the month as needed.
appleorange
Obsidian | Level 7
OK, that's what I was missing. It seems like resetting the birth dates to the beginning of the month would be the simplest solution here, thanks!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2324 views
  • 0 likes
  • 4 in conversation