Hi i have a daily stock price panel data over a period of years, i want to calculate weekly standard deviation for each stock and then use it as a regressor in a regression equation, how can i do it, please help.
i have data like this
data have;
input stockname $ price date year;
cards;
abc 26 20071205 2007
abc 46 20071206 2007
abc 36 20071207 2007
abc 26 20071208 2007
abc 26 20071210 2007
abc 35 20071212 2007
abc 75 20080123 2008
abc 45 20080224 2008
abc 55 20090612 2009
abc 51 20090613 2009
abc 57 20090614 2009
xyz 26 20071205 2007
xyz 35 20071206 2007
xyz 75 20080123 2008
xyz 45 20080612 2008
;
run;
frequency and number of stock is much higher though, i have tried to use proc means but it is not working for the panel data for me, i am really stuck up right no and cant figure out how to do it
data ghf;
set have;
format date date9.;
yrwk=year(date)*100+week(date,"U");
run;
proc sort data = ghf;
by yrwk stockname;
run;
proc means data=ghf std;
var _numeric_;
by yrwk stockname;
output out=dsd;
run;
but it gives me a messy output i.e. for every stock for each date it gives me STD MEAN and other stats too, is there any more efficient way to do this?? PLEASE HELP
Why not just limit the output to what you need? e.g.:
data need;
set sashelp.pricedata;
yrwk=year(date)*100+week(date,"U");
run;
proc summary data=need nway;
var _numeric_;
class regionName yrwk;
output out=want (drop=_:) mean= std= /autoname;
run;
Why not just limit the output to what you need? e.g.:
data need;
set sashelp.pricedata;
yrwk=year(date)*100+week(date,"U");
run;
proc summary data=need nway;
var _numeric_;
class regionName yrwk;
output out=want (drop=_:) mean= std= /autoname;
run;
For graphing you would get better results with a genuine date variable such as :
yrwk = intnx("WEEK",date,0);
format yrwk yyweeku.;
and then, if you use SGPLOT graphing proc :
series x=yrwk y=ystd / group=regionName;
xaxis type=time tickvalueformat=yyweeku. fitpolicy=thin;
PG
Then you have to do a bit of back flipping to recover the week dates (untested)...
data wantGraph;
set want;
/* transform number 200601 into string "2006W0101" and read with WEEKU9. informat */
yrwkDate = input(cats(floor(yrwk/100),"W",put(mod(yrwk,100),z2.),"01"),weeku9.);
format yrwkDate yyweeku.;
run;
proc sgplot data=wantGraph;
series x=yrwkDate y=price_std / group=regionName;
xaxis type=time tickvalueformat=yyweeku. fitpolicy=thin;
run;
PG
can anyone please tell me what week(date,"U") does?
thanks guys
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!
Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.
Find more tutorials on the SAS Users YouTube channel.