BookmarkSubscribeRSS Feed
chittamsri1_gmail_com
Calcite | Level 5

in o/p we have 3 variables stockname ,year,return

stockname  year return

tcs        2000 10%

tcs        2001 20%

tcs        2002 30%

tcs        2003 40%

tcs        2004 50%

hp         2000 20%

hp         2001 40%

hp         2002 50%

hp         2003 60%

hp         2004 70%

quest: by using above dataset we would create new data set with all the above variables and new varible 'growth' .finally i want a growth it should be automatically calculated by using below formula.give me a code for this. 

(formula) growth =(return(2001)-return(2000))

                  ----------------------------

                        return(2000)

2 REPLIES 2
Ksharp
Super User

A homework ?

data have;
input stockname $  year return : percent8.;
format return  percent8.;
cards;
tcs        2000 10%
tcs        2001 20%
tcs        2002 30%
tcs        2003 40%
tcs        2004 50%
hp         2000 20%
hp         2001 40%
hp         2002 50%
hp         2003 60%
hp         2004 70%
;
run;
data have;
set have;
g=dif(return)/lag(return);
if stockname ne lag(stockname) then call missing(g);
run;

Xia Keshan

chittamsri1_gmail_com
Calcite | Level 5

Thanks for your reply

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
  • 716 views
  • 0 likes
  • 2 in conversation