BookmarkSubscribeRSS Feed
chinna0369
Pyrite | Level 9

Hi all,

 

I am merging the below datasets but I am not getting the output which I want. Can anyone help me with this? 

data local;
	input subject $1-10 local_visit $11-20 local_date $21-30 local_time $31-40;
datalines;
101-007   WEEK 18   13JUL2022  12:49
101-007   WEEK 18   13JUL2022  12:50
101-007   WEEK 18   13JUL2022  12:51
101-007   WEEK 20   28SEP2022  14:38
101-007   WEEK 20   28SEP2022  14:39
101-007   WEEK 20   28SEP2022  14:40
101-007   WEEK 22   13APR2022  13:02
101-007   WEEK 22   13APR2022  13:03
101-007   WEEK 22   13APR2022  13:04
;
run;
proc sort; by subject; run;

data central;
	input subject $1-10 central_visit $11-20 central_date $21-30 central_time $31-40;
datalines;
101-007   WEEK 18   13JUL2022  12:30
101-007   WEEK 18   13JUL2022  12:31
101-007   WEEK 19   14JUL2022  12:32
101-007   WEEK 20   28SEP2022  14:01
101-007   WEEK 20   28SEP2022  14:02
101-007   WEEK 20   29SEP2022  14:03
101-007   WEEK 22   13APR2022  13:45
101-007   WEEK 22   13APR2022  13:46
101-007   WEEK 22   14APR2022  13:47
;
run;
proc sort; by subject; run;

data want;
	input subject $1-10 local_visit $11-20 central_visit $21-30 local_date $31-40 central_date $42-51 local_time $53-58 central_time $60-65;
datalines;
101-007   WEEK 18   WEEK 18   13JUL2022  13JUL2022  12:49  12:30
101-007   WEEK 18   WEEK 18   13JUL2022  13JUL2022  12:50  12:31
101-007   WEEK 18             13JUL2022             12:51      
101-007             WEEK 19              14JUL2022         12:51
101-007   WEEK 20   WEEK 20   28SEP2022  28SEP2022  14:38  14:01
101-007   WEEK 20   WEEK 20   28SEP2022  28SEP2022  14:39  14:02
101-007   WEEK 20   WEEK 20   28SEP2022  29SEP2022  14:40  14:03
101-007   WEEK 22   WEEK 22   13APR2022  28SEP2022  13:02  13:45
101-007   WEEK 22   WEEK 22   13APR2022  28SEP2022  13:03  13:46
101-007   WEEK 22   WEEK 22   13APR2022  24SEP2022  13:04  13:47
;
run;

I am unable to merge because of mutiple records.

 

Thanks in advance!

Anyala

 

6 REPLIES 6
PaigeMiller
Diamond | Level 26

What is the logic you want when merging data sets here? I don't think we can generalize or infer what you want from the one mismatch in your two tables. Please provide more details.

--
Paige Miller
chinna0369
Pyrite | Level 9
I want to combine two datasets by visits and compare dates and time for each visit from two datasets.
data_null__
Jade | Level 19

PROC COMPARE

chinna0369
Pyrite | Level 9
No, I would like to create a dataset which is shown in example the
dataset name called want to show variables side by side from each dataset for manual comaparision.
ballardw
Super User

Suggestion: Don't worry much about the order of variables in a data set. Any of the report procedures can write variables in any order that you prefer.

Proc Print the data concerned and list the variables in the order you want them on a VAR statement.

 

And do you really have that many "date" variables that are character??? That is basically shooting yourself in the foot as pretty much the first thing involved for most analysis or manipulation is going to be create a date value instead of character.

PaigeMiller
Diamond | Level 26

@chinna0369 wrote:
I want to combine two datasets by visits and compare dates and time for each visit from two datasets.

I ask you to provide the logic, and you repeat the same information as in your original message. That's not what I want. I want a more complete explanation of how to merge these data sets and create the desired output. The example you give has only one mismatch and I do not think I can generalize from one mismatch what to do in that situation.

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 6 replies
  • 1616 views
  • 0 likes
  • 4 in conversation