BookmarkSubscribeRSS Feed
nazmul
Quartz | Level 8

Dear Everyone,

 

I am trying to get a parameter value (R) for each observation by solving the following equation. I put my SAS codes below. However, I am not getting any answers. I believe my code is wrong. I then use the excel solver to estimate the value (R) for your reference. I also put the data below. Please help me with your SAS code to solve the problem.

 

I just found the following link https://communities.sas.com/t5/General-SAS-Programming/Solve-Equation/td-p/231581 where they used proc model to solve an equation but I am not sure how to apply it in my case. Could you please help me?

 

SAS code

 

proc nlp noprint data=S1 absgconv=1e-15 OUTEST=T1; by obs;
bounds R>=0, R<=1;
min f;
decvar R=1;
f = abs(Price2_Y0-(B0_T1+((FROE1_T1_Med-R)/(1+R))*B0_T1
+((FROE2_T1_Med-R)/((1+R)**2))*B1_T1_Med
+((FROE3_T1_Med-R)/((1+R)**3))*B2_T1_Med
+((FROE4_T1_Med_I1-R)/((1+R)**4))*B3_T1_Med
+((FROE5_T1_Med_I1-R)/((1+R)**5))*B4_T1_Med_I1
+((FROE6_T1_Med_I1-R)/((1+R)**6))*B5_T1_Med_I1
+((FROE7_T1_Med_I1-R)/((1+R)**7))*B6_T1_Med_I1
+((FROE8_T1_Med_I1-R)/((1+R)**8))*B7_T1_Med_I1
+((FROE9_T1_Med_I1-R)/((1+R)**9))*B8_T1_Med_I1
+((FROE10_T1_Med_I1-R)/((1+R)**10))*B9_T1_Med_I1
+((FROE11_T1_Med_I1-R)/((1+R)**11))*B10_T1_Med_I1
+((FROE12_T1_Med_I1-R)/(R*(1+R)**11))*B11_T1_Med_I1));
run;
data T1; set T1;
if _TYPE_='PARMS';
keep obs R; run;
data O1; merge S1 (in=xx) T1(in=yy); by obs; if xx and yy; run;

 

Sample log file: I get errors for every single observation

 

NOTE: The above message was for the following BY group:
obs=56822
ERROR: There are references to missing variables when the program code is
executed for _OBS_= 1
WARNING: Your program statements cannot be executed completely.
WARNING: In a total of 786 calls an error occurred during execution of the
program statements. NLP attempted to recover by using a shorter step
size.
NOTE: The above message was for the following BY group:
obs=56823
WARNING: Your program statements cannot be executed completely.
WARNING: Your program statements cannot be executed completely.
ERROR: NRRIDG Optimization cannot be completed.
WARNING: Optimization routine cannot improve the function value.
WARNING: In a total of 788 calls an error occurred during execution of the
program statements. NLP attempted to recover by using a shorter step

 

data

 

obsB0_T1Price2_Y0B1_T1_MedB2_T1_MedB3_T1_MedB4_T1_Med_I1B5_T1_Med_I1B6_T1_Med_I1B7_T1_Med_I1B8_T1_Med_I1B9_T1_Med_I1B10_T1_Med_I1B11_T1_Med_I1FROE1_T1_MedFROE2_T1_MedFROE3_T1_MedFROE4_T1_Med_I1FROE5_T1_Med_I1FROE6_T1_Med_I1FROE7_T1_Med_I1FROE8_T1_Med_I1FROE9_T1_Med_I1FROE10_T1_Med_I1FROE11_T1_Med_I1FROE12_T1_Med_I1R_SASR_excel123456789101112Sumdif
112.0417.512.9614.1115.4617.0918619.0678621.4675824.3932527.9768432.3897837.8561744.670830.0709880.0815020.0873220.0954760.103630.1117840.1199370.1280910.1362450.1443990.1525530.160707111%-0.4457-0.3212-0.25475-0.16857-0.08567-0.003770.0793540.1660520.2588720.3607040.4749325.39974617.5-3.5E-06
24.194310.61-2.66464-9.81995-17.441-25.5259-31.7687-34.3922-32.9443-28.2985-22.0324-15.6856-10.2866-0.60796-0.1721-0.10321-0.07481-0.04641-0.018020.010380.0387760.0671720.0955680.1239650.1523610.5323310%-2.693330.5941591.4841832.0623632.2958772.086371.5460390.90090.352807-0.00055-0.16366-2.0494110.610054.7E-05
353.42168.1163.0879474.1782286.74057100.6832116.0122132.7046150.7046169.9214190.2273211.4572233.40980.1540710.1503140.1456070.1392260.1328440.1264630.1200820.1137010.107320.1009390.0945580.08817716%4.802855.1453185.4193625.5445265.5952825.56355.4427935.2288794.9198754.5165134.02224858.48874168.1099-0.00012
412.678539.2612.36411.9933511.6114611.2285510.8455510.4633610.082859.7048349.3301028.9593968.5934150.0452930.0550310.0585630.0607220.0628810.065040.0671990.0693580.0715170.0736750.0758340.0779930.0188972%0.3311720.4330540.4524430.4532820.4523930.4499010.4459310.4406040.4340440.426370.41769921.8446139.260015.8E-06
511.2452.8713.1615.3717.8920.7274323.9049927.4440831.3642335.6825340.4129445.5656751.146540.1458970.1437870.1408610.1368930.1329240.1289560.1249880.121020.1170520.1130840.1091150.10514715%0.9942571.0806891.1603641.2251191.2846771.3376771.3827581.4185791.443861.4574131.4581727.3864352.87-3.7E-06
4 REPLIES 4
Tom
Super User Tom
Super User

How is it going to solve for anything if there is only one observation?  Isn't it just an equation you want to calculate at that point?

nazmul
Quartz | Level 8

Dear Tom,

 

I am just solving a basic equation where you know all the values except one (In this case R). I simply do not know how to solve it in SAS. Could you please suggest how can I do it? If possible please suggest a specific code. 

PGStats
Opal | Level 21

It says that one of your equation variables doesn't exist in your data. Check for a possible typo. Also, shouldn't the last exponent for (1+R) be 12?

PG
nazmul
Quartz | Level 8

Dear PGStats,

 

The only variable not available is R and I want to calculate the variable solving the equation. I checked the equation and match the variable names to the sample data I provided in this post. All variables other than R are present in the dataset.

 

Thank you for pointing the last exponent. However, the equation is correct.

 

If possible, could you please provide me the code and log file to check. I highly appreciate your help.

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
  • 4 replies
  • 549 views
  • 1 like
  • 3 in conversation