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
@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)?
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.
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).
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.