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

Hi ,

i have a scenario to

Output If the Site or Subject or Visit number or Visit Date is either present in the "A" data set but is missing from the "B" data set or vice versa?

any suggestions will be helpful, Thanks.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

As @Vijay77 asked for: "...present in the "A" data set but is missing from the "B" data set or vice versa?"

a light change need to last step of @Jagadishkatam :

data want;
merge dataset_a(in=a) dataset_b(in=b);
by site subject visit_number visit_date;
if not (a and b);   /* line changed */
run;

View solution in original post

7 REPLIES 7
Jagadishkatam
Amethyst | Level 16

You can use the merge statement with by group to output such records or else you can also use the proc sql joins.

 

An example data would help to get better inputs.

Thanks,
Jag
Vijay77
Fluorite | Level 6

Hi,

 

consider these as a example data

 

A                                                                                                             B

site  subject  Visit number Visit Date                                         site  subject  Visit number Visit Date

101 123        10                  12aug2019                                     101   123        15                12aug2019  *here visit number diff so i should get as missing visnumber

101 134         05                 14aug2019                                     101   134        05                 .                   *here output missing date from b

101 135        09                     .                                                   101   135        09                 14aug2019  *here output missing date from a

Jagadishkatam
Amethyst | Level 16

please try the below code

 

proc sort data=dataset_a;
by site subject visit_number visit_date;
run;

proc sort data=dataset_b;
by site subject visit_number visit_date;
run;

data want;
merge dataset_a(in=a) dataset_b(in=b);
by site subject visit_number visit_date;
if b and not a;
run;
Thanks,
Jag
Shmuel
Garnet | Level 18

As @Vijay77 asked for: "...present in the "A" data set but is missing from the "B" data set or vice versa?"

a light change need to last step of @Jagadishkatam :

data want;
merge dataset_a(in=a) dataset_b(in=b);
by site subject visit_number visit_date;
if not (a and b);   /* line changed */
run;
Vijay77
Fluorite | Level 6
Will this work for missing dates from either A or B with same site subject and visit
Shmuel
Garnet | Level 18

Yes. of course. The checking is done after merging. 

Vijay77
Fluorite | Level 6
for missing dates:
merge a(in=x) b(in=y);
by site subjid visit;
if (x and y);
if missing(vis_date); run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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