BookmarkSubscribeRSS Feed
NEEDSASHELP
Calcite | Level 5

Hi Everyone,

I was hoping if I can get some help for codes to do the following - there are 3 datasets in the Zipfile that will help make sense of the questons as a reference.

1). In file regresstest.dat, what is the code to regress RE_RF = a + B(RM_RF), but specifically between row 8 to 20 ?
         proc reg
         data = regresstest.dat;
         model RE_RF = RM_RF - (what to I put here so I control which dates I include in the regression)

2). In file newgg5po (stands for new dataset, government traders, stock 5po)
On row 5 and 6 you see the same date (20051221), column "shoc" (2nd last column) have 2 corresponding values for 2 government trades on that day for that stock. What is the code so I only have 1 row for each date - so that the corresponding "shoc" value for date (20051221) is the sum of the values in row 5 and 6.
Also some days there are no trades - how to I fill these rows so there is a date - with 0 for "shoc"

3).  Assume I want to sum row 1 of the "shoc" column from newgg5po with row 20 of the "shoc" column from newgg60n, and then row 2, row 3 .... for row 21,22 . .. and have the output on a new data file. What is the code for that?

Thank you so much in advance,

8 REPLIES 8
Tom
Super User Tom
Super User

You did not include any SAS datasets in the Zip file.  There is just a DLL file, which I decline to expand as I have no idea what it might do to my computer.

1) To limit the observations (rows) included in an analysis you could use a WHERE statement.

2) You could use PROC SUMMARY to create a new files that has the SUM of variables. Use a BY or CLASS statement to make it group be the variables (columns) that uniquely identify the groups.  To fill in the zeros it depends one what is missing.  If you have an observation already and are just missing a value then use program logic to make the variable be zero instead.  If x=. then x=0; or x=coallese(x,0);

3) Not sure what you are talking about here. Normally you would refer to matching of observations (rows) from one dataset with another by referencing the variables (columns) that need to match.  So if there are variables that indicate row1 of dataset A should be matched with row2 of dataset B then you can merge be those.  But it really sounds like what you want to do is more like your second question. In that case just concatenate the datasets using a DATA step with a SET statement and then use PROC SUMMARY as in the second question.

FriedEgg
SAS Employee

You already asked these same questions:

http://communities.sas.com/thread/30965?tstart=0

NEEDSASHELP
Calcite | Level 5

Yeah sorry, I didnt know how to upload data files in reply - so I thought I should re-post with data files uploaded for better reference as requested by a helper in the previous thread.

I was hoping for specific codes as the data files are now available. Thx

FriedEgg
SAS Employee

You didn't upload data or code, you uploaded a random dll file.

NEEDSASHELP
Calcite | Level 5

ARGGGGGGGGGG THANKS so much - I'll upload the files first thing when I get home from work. PS - Is there a way to upload data files without posting new threaD?

FriedEgg
SAS Employee

When you click on reply in the upper right hand corner you can choose to utilize the advanced editor.  That will allow you to upload files via a normal reply.

NEEDSASHELP
Calcite | Level 5

Thanks so much FriedEgg - attached is the correct datfiles.

Ksharp
Super User

For 1)

proc reg
         data = regresstest(firstobs=8 obs=20);
         model RE_RF = RM_RF

2) use first.var and last.var

use If x=. then x=0; or x=coallese(x,0); to instead of x missing value.

3)first sub dataset.

data a(rename=(shoc=_shoc));

set a(firstobs=20);

count+1;

run;

data b;

count+1;

run;

data want;

merge a b;

by count;

want_shoc=shoc+_shoc;

run;

the code above is not tested. just a reference.

Ksharp

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