BookmarkSubscribeRSS Feed
apxprdtr10
Calcite | Level 5

Hi all,

 

I have two dataset data1 and data2.

 

data1.

store_postcode

1

2

3

4

5

6

7

8

9

 

 

data2.

store_postcode price month

2 32 1

5 65 3

3 87 2

1 89 3

6 56 5

8 45 7

4 67 4

7 49 8

 

Now i want to merge dataset2 in dataset1 by store_postcode.

 

Thanks.

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sort d1 and d2 by store_postcode then:

data want;
  merge d1 d2;
  by store_postcode;
run;

Is that your question as I don't see anything conditional?  

apxprdtr10
Calcite | Level 5

as you can see there is no store_postcode named 9 in dataset2. and that's where i want conditional merging.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

This does not mean anything to me.  Do you mean you only want values which appear in one dataset?  If so then add:

data want;
  merge d1 (in=a) d2 (in=b);
  by store_postcode;
if a and b; run;

The above will keep only observations where data is in both datasets.  You could do:

if a;

For only those records in the first, or

if b;

for those only in the second. 

ballardw
Super User

Show your desired output. The example is small enough that should not be difficult.

A description that can be interpreted in multiple ways leads to lots of clarifying questions.

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