BookmarkSubscribeRSS Feed
pdhokriya
Pyrite | Level 9

Hello,

 

I have 5 datasets (a,b,c,d,e) and all these 5 datasets has xyz variable with same datatype, please suggest in 1 query how can I pull observations (in 1 dataset) from xyz from all 5 datasets.

 

From: Priyanka

4 REPLIES 4
PaigeMiller
Diamond | Level 26

@pdhokriya wrote:

 

I have 5 datasets (a,b,c,d,e) and all these 5 datasets has xyz variable with same datatype, please suggest in 1 query how can I pull observations (in 1 dataset) from xyz from all 5 datasets.


Given the wording above, it is not clear if you are trying to find when observations have the same value of XYZ in all five data sets, or are you trying to find cases where a value in XYZ appears in more than one (but not all five) data sets, or even the situation where a value in XYZ appears in just one data set. Clarification would help.

 

Also, do you want to combine these data sets horizontally (MERGE or JOIN) or vertically (SET or UNION)?

--
Paige Miller
Quentin
Super User

Without much more information, sounds like a LEFT JOIN.

 

If you can post a small example of work.A, work.B, and work.C  (so DATA steps using CARDS statement to create each, maybe 5 rows of data, 3 variables) and then post the output you would want, along with the code you have tried, it will help people help you.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Lisa Mendez & Richann Watson present Get Tipsy with Debugging Tips for SAS® Code: The After Party on Wednesday Jul 16.
Register now at https://www.basug.org/events.
ballardw
Super User

Strongly suggest that you provide some small examples and what the result is supposed to look like.

For example are any other variables to be included in the result? If they are have you verified the other variables that have the same name are of the same data type and length?

Is there supposed to be any indication of which data set a specific value came from?

How many values are involved? Do they need to change? (Goes to how to provide the list for selection, 2 or three are easy to place directly in code, 200 not so much).

Reeza
Super User
data want;
set a b c d e;
keep xyz;
run;

I suspect this isn't quite what you want so you'll need to provide more information - fake examples of your situation are fine.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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