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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 562 views
  • 0 likes
  • 2 in conversation