datatset P
Name sex
aa 1
aa 0
aa 1
bb 0
bb 1
bb 0
datatset L
Name amount
aa 100
aa 200
aa 300
bb 400
bb 500
bb 600
I want to split these dataset P and L based on name, create new datasets Z which has name as aa from both dataset.similarly for dataset K
output:
dataset z
Name sex Name amount
aa 1 aa 100
aa 0 aa 200
aa 1 aa 300
dataset K:
Name sex Name amount
bb 1 bb 400
bb 0 bb 500
bb 1 bb 600
I dont want to do merge. I am looking do this using set statement.
@suresh123 wrote:
I dont want to do merge. I am looking do this using set statement.
This can be done easily via a MERGE statement. I don't see how it can be done using SET.
Your plan needs a little correction first. It's not possible to have two variables called NAME in the same data set. And the values for SEX for bb look like they should be 0 1 0, not 1 0 1.
At any rate, if both data sets contain the same number of observations for aa and bb, you could use:
data z k;
set p;
set L;
if name='aa' then output z;
else output k;
run;
Variations in the code might depend on how many NAME values exist, but this program at least works for the data you provided.
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.