BookmarkSubscribeRSS Feed
hkim3677
Calcite | Level 5

Hi, 

 

I need to merge two different period samples.

For example,

The first data set is like..

 

Data example1;

input id year c1 c2;

datalines;

1 1990 1 0

1 1991 1 1

1 1992 0 1

1 1993 0 0

2 1992 0 1

2 1993 0 0

;

run;

 

Data example2;

input id year c1 c2;

datalines;

1 1994 0 1

1 1995 0 1

2 1994 0 0

2 1995 0 0

3 1995 0 1

3 1996 1 0

;

run;

 

After merging two data sets, I need to have the following dataset.. like..

 

Data want;

input id year c1 c2;

datalines;

1 1990 1 0

1 1991 1 1

1 1992 0 1

1 1993 0 0

1 1994 0 1

2 1992 0 1

2 1993 0 0

2 1994 0 1

2 1995 0 0

3 1995 0 1

3 1996 1 0

;

run;

 

How can I merge two different period samples?

2 REPLIES 2
Reeza
Super User

This isn't a merge exactly, it's an append or union. 

 

You can use PROC APPEND or a SET statement in a data step.

 

data combined;

set example1 example2;

run;

You can then use PROC SORT to get the desired order.

 

 

 

 

ChrisNZ
Tourmaline | Level 20

Or use a BY statements to avoid re-sorting if the tables are already sorted.

data combined;
  set example1 example2;
  by id year;
run;

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 344 views
  • 2 likes
  • 3 in conversation