BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Is there a way to recover the original non-merge-matched observations without any additional variables?

For example, suppose that I am trying to obtain three separate data sets using the following codes:

data July31_11
July31_10
July31_01;
Merge one (in=ones) two (in=twos);
by id sex age state;
if ones=1 and twos=1 then output July31_11;
if ones=1 and twos=0 then output July31_10;
if ones=0 and twos=1 then output July31_01;
run;

My problem is that although the July31_10 and July31_01 give me the non-merge-matched cases (cases whether one of the data set did not contribute to the current observation because of missing values or other reasons), these will contain anyway the same total number of variables as the July31_11 data set will have.

I am interested in obtain (“recover”) the non-contributing cases in their original form (as they was in their respective original data set) with the original set of variables.

Do you have any suggestion?

Thanks
1 REPLY 1
Olivier
Pyrite | Level 9
Hi Caramel.
I suggest you collect the variables names before merging, and then only KEEP them in the output datasets. Either you name each list of variable names, or do it automatically -- as the program below suggests to do.
[pre]
PROC CONTENTS DATA=one OUT=dico_one NOPRINT ;
RUN ;
PROC CONTENTS DATA=two OUT=dico_two NOPRINT ;
RUN ;
PROC SQL NOPRINT ;
SELECT LEFT(TRIM(name)) INTO list_one SEPARATED BY " "
FROM dico_one ;
SELECT LEFT(TRIM(name)) INTO list_two SEPARATED BY " "
FROM dico_two ;
QUIT ;
data July31_11
July31_10 (KEEP=&list_one)
July31_01 (KEEP=&list_two) ;
Merge one (in=ones) two (in=twos);
by id sex age state;
if ones=1 and twos=1 then output July31_11;
if ones=1 and twos=0 then output July31_10;
if ones=0 and twos=1 then output July31_01;
run;
[/pre]
Olivier

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 558 views
  • 0 likes
  • 2 in conversation