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
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?
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.