BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Emma8
Quartz | Level 8
Hi. I would like to select distinct values from 3 datasets without merging it,
For example,
Age variable from 3 datasets:
Data 1 data 2 data 3
1 4 7
3 5 8
5 7 9
1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

The problem could be solved by using data-step merge without by ... why don't you want to use merge?

 

proc sort data=a out=a_sorted(keep=Age) nodupkey;
	by Age;
run;

proc sort data=b out=b_sorted(keep=Age) nodupkey;
	by Age;
run;

proc sort data=c out=c_sorted(keep=Age) nodupkey;
	by Age;
run;

data compare;
	merge
		a_sorted(rename=(Age = Age_A))
		b_sorted(rename=(Age = Age_B))
		c_sorted(rename=(Age = Age_C))
	;
run;

View solution in original post

3 REPLIES 3
Patrick
Opal | Level 21

Would the desired result be a list of distinct values per data set or the list of distinct values over all data sets?

Emma8
Quartz | Level 8
District values over all datasets.—I would like to compare across column and rows so—it would nice if formatted as in my first message notes. Thank you.
andreas_lds
Jade | Level 19

The problem could be solved by using data-step merge without by ... why don't you want to use merge?

 

proc sort data=a out=a_sorted(keep=Age) nodupkey;
	by Age;
run;

proc sort data=b out=b_sorted(keep=Age) nodupkey;
	by Age;
run;

proc sort data=c out=c_sorted(keep=Age) nodupkey;
	by Age;
run;

data compare;
	merge
		a_sorted(rename=(Age = Age_A))
		b_sorted(rename=(Age = Age_B))
		c_sorted(rename=(Age = Age_C))
	;
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1029 views
  • 1 like
  • 3 in conversation