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

 

Hello,

I have two tables :

 

Data t1 ;

Input texte1 ;

Cards ;

ERGO

ERGY

DERMU

FERMI

VERMO

;

Run

 

 

Data t2 ;

Input texte2 ;

Cards ;

ERGO

CRGY

DERMU

ZERMI

VERMO

;

Run

 

I would like to create a 3rd table with items that are only present in one.

 

And get :

 

Texte1   Texte2

ERGY     CRGY

FERMI  ZERMI

 

thank you for your help

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Run a proc sort nodupkey on both datasets.  As there is not link between the two its hard to say how to put them together:

proc sort data=t1 nodupkey;
  by texte1;
run;
proc sort data=t2 nodupkey;
  by texte2;
run;
data want;
  merge t1 t2;
  by ...;
run;

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Run a proc sort nodupkey on both datasets.  As there is not link between the two its hard to say how to put them together:

proc sort data=t1 nodupkey;
  by texte1;
run;
proc sort data=t2 nodupkey;
  by texte2;
run;
data want;
  merge t1 t2;
  by ...;
run;
Ksharp
Super User
Data t1 ;  
Input texte1 $; 
Cards ;  
ERGO  
ERGY  
DERMU  
FERMI  
VERMO  
;  
Run;        
Data t2 ;  
Input texte2 $ ;  
Cards ;  
ERGO  
CRGY  
DERMU  
ZERMI  
VERMO  
;  
Run;
proc sql;
create table x1 as
 select texte1 from t1
 except
 select texte2 from t2 ;

create table x2 as
 select texte2 from t2
 except
 select texte1 from t1 ;
quit;
data want;
 merge x1 x2;
run;
soham_sas
Quartz | Level 8

Hi you can try the below code , but it will give you texte1 and texte2 value with some blank (missing) observations , you have to write one more step to remove the blank and keep only the unique value 

 

can any one suggest how to do that in a single step 

 

 

proc  sql;
create table want as 
select  texte1 ,  texte2 from t1  full join t2
on texte1 = texte2
where texte1 in (select texte1 from t1 left join t2 on texte1=texte2 where texte2 is null)
or texte2 in (select texte2 from t2 left join t1 on texte2=texte1 where texte1 is null);
quit;

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