BookmarkSubscribeRSS Feed
econfkw
Calcite | Level 5


I want to merge temp1 and temp2  as temp4.

tem.sas is the code. It doesn't work. Basically, it cannot sort when firm=.

Please help me a little.

thanks

2 REPLIES 2
Reeza
Super User

The code is correct. What isn't working as you'd expect.

You sort and merge by date not firm, so where does firm come into play?

AncaTilea
Pyrite | Level 9

Hi.

You can't get the desired data set (temp4) because there is no firm information for data = 5. Please see below:

data temp1;

input date    firm;

cards;

1    1

2    1

3    1

4    1

1    2

2    2

3    2

;

data temp2;

input date    stock $;

cards;

1    a

2    b

3    c

4    d

5    e

;

data want;

input date    firm     stock $;

cards;

1    1    a

2    1    b

3    1    c

4    1    d

5    1    .

1    2    a

2    2    b

3    2    c

;

It seems to me that given your data set temp1 - the one that has the information on date and firm...there is no way of knowing that for date 5 you will have firm = 1 (like you want in your desired data set (temp4))

Unless you specifically tell us that for any missing information on firm carry down the information form prior record....??


So, below is the code you provide (which is correct):

proc sort data=temp1;

by date;

run;

proc sort data=temp2;

by date;

run;

data temp3;

merge temp1(in=frodo) temp2(in=prodo);

by date;

if prodo;

run;

This works, but without you specifically telling us that you want a carry down of value when missing, you can't get the desired output.


I am talking a bit circular, I think.


I hope this helps a bit.


Good luck,

Anca.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1137 views
  • 0 likes
  • 3 in conversation