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.
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.
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.