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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 609 views
  • 0 likes
  • 3 in conversation