BookmarkSubscribeRSS Feed
suresh123
Calcite | Level 5

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.

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Astounding
PROC Star

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2 replies
  • 1121 views
  • 0 likes
  • 3 in conversation