BookmarkSubscribeRSS Feed
Cassie2
Calcite | Level 5

Hi all, 

 

I have a dataset that are similar to the following. It's the monthly stock prices of about 200 companies. Now I want to generate the monthly return of each stock, which I defined as : (Rt/Rt-1) -1 . How should write the code to do this? 

 

Thank you very much.

 

NameDANANG RUBBERSAIGON THUONG TIN COMMERCIALASIA COMMERCIALCHUONG DUONG BEVERAGESTHANG LONG WINEPETROVIETNAM FCM.DONG PHU RUBBERHOA BINH RUBBERGENERAL MATERIALTHONG NHAT RUBBER
CodeVT:DRC(P)VT:STB(P)VT:ACB(P)VT:SCD(P)VT:VTL(P)VT:DPM(P)VT:DPR(P)VT:HRC(P)VT:HSI(P)VT:TNC(P)
1/1/0813498.7530110.9749638.724000021994.38740008500096000.54100036500
2/1/0813169.5129651.2641527.033360022494.25685008200084571.883460031500
3/1/088505.3122525.7530872.862380020344.8535005800054000.312580024200
4/1/086200.6517193.1328481.731790012896.7490004940039143.072130019300
5/1/085816.5415400.2725091.761910011846.97535005600035714.482380019000
6/1/084356.911107914316.54177009997.44402004450026742.991860014000
7/1/083709.4110343.4614861.352210012146.89440005400025428.711850013500
8/1/084402.9910527.3518523.71184009897.47580006200027714.432410014700
9/1/085788.6414205.0228935.742530010547.3650006950036000.22420017000
10/1/084532.4911033.0324254.92190009747.51580006300028571.591900014900
11/1/083030.310113.6120314.09180006998.21452003530014742.941350011000
12/1/0823319332.119610.37162006498.34362003040018400.11135009800
1/1/092175.68458.6517884.61160006998.21345003040013942.94117008200
2/1/092201.57861.0317820.51157007298.13330003100013028.64122007700
3/1/092292.156987.5816025.65121006648.3283002400011085.7897006700
4/1/093082.17769.0919230.77124006748.27331003190014857.23118009400
5/1/093613.049653.923717.96131008247.89365003180014628.661130010500
6/1/097834.7312779.9328461.551570011946.95442004670021200.121330015600
7/1/0910036.2315262.3629871.811560014596.27405004050019028.681190013300
8/1/0911007.4816687.4529871.811600014896.19474004580020171.551220014200
9/1/0913338.4718020.6130576.941920013746.48497006200025142.991320016300
10/1/0921885.4718564.4829358.982060013996.42471006000025428.711300016300
11/1/0919813.4716955.1727564.112940014996.16422005700024685.861330016800
12/1/0916316.9815288.4125287.412480014946.18381006100023371.551170015800
1/1/1015798.9713851.5224182.32690014646.25340005800021371.551130014300

 

1 REPLY 1
ballardw
Super User

Since you don't show a variable or anything labeled as "Rt" you need to describe in terms of you data what exactly is meant by "(Rt/Rt-1) -1 ".

 

You probably need to reshape your data so that you have something that looks more like:

Name Code Date Value

 

Do you have a SAS data set? That looks very improbable for the sort of calculation I think you intend as all of those values under the names are going to be character.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 261 views
  • 0 likes
  • 2 in conversation