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

Hi,

 

1.one of my dataset contains date variable in 03/14/2018 format . There are many more variables too.

proc content shows the below about date -

 SAS Output

Operation_DateChar10$10.$10.Operation Date

 

2. another dataset contains date variable looking like this 11Jun2018

proc contents on this dataset shows below about the date

SAS Output

opdateNum8DATE9.DATE9.opdate

 

I want to merge both dataset by patient id and date, but i do not know how to convert both of the dates to same format to be able to merge. Please help.

 

      
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@Kyra wrote:

Hi,

 

1.one of my dataset contains date variable in 03/14/2018 format . There are many more variables too.

proc content shows the below about date -

 SAS Output

Operation_Date Char 10 $10. $10. Operation Date

 

2. another dataset contains date variable looking like this 11Jun2018

proc contents on this dataset shows below about the date

SAS Output

opdate Num 8 DATE9. DATE9. opdate

 

I want to merge both dataset by patient id and date, but i do not know how to convert both of the dates to same format to be able to merge. Please help.

 

           

You have a choice as to which set to modify by adding a variable of the correct type and value range.

 

I suggest adding a date valued variable using input with Operation_date.

In a data step:

data temp;

   set have;

   opdate = input(operation_date,mmddyy10.);

   format opdate date9.;

run;

and then merge the resulting set using opdate after appropriate sorting.

 

There are many reasons to ensure date, time or datetime appearing values are actual SAS date, time or datetime valued variables created with the correct informat or functions.

 

 

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

There is no problem merging on a date variable that might be using different display formats.  But that is NOT what you have. Instead you have one date variable and one character string. So you will need to convert the character string into a date so you can match the date values in your other dataset.

data one_fixed;
  set one;
  length opdate 8;
  opdate=input(operation_date,mmddyy10.);
  format opdate date9.;
run;
proc sort;
  by patid opdate;
run;

data want;
  merge one_fixed two ;
  by patid opdate;
run;
ballardw
Super User

@Kyra wrote:

Hi,

 

1.one of my dataset contains date variable in 03/14/2018 format . There are many more variables too.

proc content shows the below about date -

 SAS Output

Operation_Date Char 10 $10. $10. Operation Date

 

2. another dataset contains date variable looking like this 11Jun2018

proc contents on this dataset shows below about the date

SAS Output

opdate Num 8 DATE9. DATE9. opdate

 

I want to merge both dataset by patient id and date, but i do not know how to convert both of the dates to same format to be able to merge. Please help.

 

           

You have a choice as to which set to modify by adding a variable of the correct type and value range.

 

I suggest adding a date valued variable using input with Operation_date.

In a data step:

data temp;

   set have;

   opdate = input(operation_date,mmddyy10.);

   format opdate date9.;

run;

and then merge the resulting set using opdate after appropriate sorting.

 

There are many reasons to ensure date, time or datetime appearing values are actual SAS date, time or datetime valued variables created with the correct informat or functions.

 

 

Kyra
Quartz | Level 8

Thank you very much.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 2642 views
  • 0 likes
  • 3 in conversation