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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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