Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 07-23-2021 07:07 AM
(480 views)

Hello ....

I am trying to solve two equations simultaneously. I couldn't find anything for IML. Instead, I found "proc model" and "solve" so I used submit and endsubmit inside my IML. The problem which I am facing now is that I can't export the roots to IML. I would appreciate your help here. Thank you

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

1. You can solve a system of nonlinear equations in SAS/IML by using the NLPLM or NLPHQN subroutines. See the article, "Solve a system of nonlinear equations with SAS."

2. I presume you meant to specify the GAMMA function in SAS as part of the nonlinear equations. PROC MODEL is failing because there is not 'GAMA' function in SAS (one M).

3. Don't worry about the color-coding in the editor. The editor gets confused by the SUBMIT/ENDSUBMIT block. When it sees a RUN or QUIT statement, it thinks a procedure has exited. It colors the PRINT statement red because it hasn't seen another 'PROC' statement after the RUN. Of course, if you eliminate the SUBMIT block, that issue will vanish.

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

1. You can solve a system of nonlinear equations in SAS/IML by using the NLPLM or NLPHQN subroutines. See the article, "Solve a system of nonlinear equations with SAS."

2. I presume you meant to specify the GAMMA function in SAS as part of the nonlinear equations. PROC MODEL is failing because there is not 'GAMA' function in SAS (one M).

3. Don't worry about the color-coding in the editor. The editor gets confused by the SUBMIT/ENDSUBMIT block. When it sees a RUN or QUIT statement, it thinks a procedure has exited. It colors the PRINT statement red because it hasn't seen another 'PROC' statement after the RUN. Of course, if you eliminate the SUBMIT block, that issue will vanish.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thank you so much for the reply.

Yes, I meant gamma and it was my mistake. I also looked at the link which you sent me but I like to know if the procedure that I used works?

Moreover, after I fixed the spelling I received an error, regarding "n" but I am not using it inside the procedure? please see attached log file.

Thank you again

NOTE: Copyright (c) 2002-2012 by SAS Institute Inc., Cary, NC, USA.

NOTE: SAS (r) Proprietary Software 9.4 (TS1M2)

Licensed to UNIVERSITY OF JORDAN, Site 70235184.

NOTE: This session is executing on the X64_8PRO platform.

NOTE: Updated analytical products:

SAS/STAT 13.2

SAS/ETS 13.2

SAS/OR 13.2

SAS/IML 13.2

SAS/QC 13.2

NOTE: Additional host information:

X64_8PRO WIN 6.2.9200 Workstation

NOTE: SAS initialization used:

real time 0.92 seconds

cpu time 0.62 seconds

1 /*Solve system of non linear equations */

2

3 title1 'Solving a Simultaneous System';

4 data test;

5 input a b @@;

6 datalines;

NOTE: SAS went to a new line when INPUT statement reached past the end of a line.

NOTE: The data set WORK.TEST has 3 observations and 2 variables.

NOTE: DATA statement used (Total process time):

real time 0.09 seconds

cpu time 0.00 seconds

8 ;

9

NOTE: Writing HTML Body file: sashtml.htm

10 proc model data=test;

11 eq.sqrt = sqrt(x) - y;

12 eq.hyperbola = a + b / x - y;

13 solve x y / solveprint;

14 id a b;

15 run;

16

NOTE: PROCEDURE MODEL used (Total process time):

real time 28:52.50

cpu time 14.54 seconds

17 proc iml;

NOTE: IML Ready

18

19 seed=12345;

19 ! k=1;

20

21 alpha=2;

21 ! lambda=2;

22

23

24 n=100;

24 ! m=n;

24 ! R=J(m,1,0);

25

26 print alpha lambda;

27

28

29

30 W=J(m,1,0);

30 ! V=J(m,1,0);

30 ! X_p=J(m,1,0);

30 ! X_A=J(m,1,0);

30 ! U=J(m,1,0);

31

32 X=J(m,1,0);

33

34 do i=1 to m;

35 W[i]=Uniform(seed);

36 end;

37

38 S=1+R[m];

39 V[1]=W[1]**(1/S);

40

41 do i=2 to m;

42 S=S+(1+R[m-i+1]);

43 V[i]=W[i]**(1/S);

44 end;

45

46 do i=1 to m;

47

48 U[i]=1-prod( V[ m:( m-i+1)] );

48 ! ** the U's are the required progressively type II from U(0,1);

49

50 END;

51

52

53 X=( 1-(1-U)##(1/alpha) )##(1/lambda);

54

55

56 print X;

57

58 quit;

NOTE: Exiting IML.

NOTE: PROCEDURE IML used (Total process time):

real time 0.06 seconds

cpu time 0.06 seconds

59

60 proc iml;

NOTE: IML Ready

61

62 seed=12345;

62 ! k=1;

63

64 alpha=2;

64 ! lambda=2;

65

66

67 n=10;

67 ! m=n;

67 ! R=J(m,1,0);

68

69 print alpha lambda;

70

71

72

73 W=J(m,1,0);

73 ! V=J(m,1,0);

73 ! X_p=J(m,1,0);

73 ! X_A=J(m,1,0);

73 ! U=J(m,1,0);

74

75 X=J(m,1,0);

76

77 do i=1 to m;

78 W[i]=Uniform(seed);

79 end;

80

81 S=1+R[m];

82 V[1]=W[1]**(1/S);

83

84 do i=2 to m;

85 S=S+(1+R[m-i+1]);

86 V[i]=W[i]**(1/S);

87 end;

88

89 do i=1 to m;

90

91 U[i]=1-prod( V[ m:( m-i+1)] );

91 ! ** the U's are the required progressively type II from U(0,1);

92

93 END;

94

95

96 X=( 1-(1-U)##(1/alpha) )##(1/lambda);

97

98

99 print X;

100

101 quit;

NOTE: Exiting IML.

NOTE: PROCEDURE IML used (Total process time):

real time 0.03 seconds

cpu time 0.03 seconds

102

103 proc iml;

NOTE: IML Ready

104

105 seed=12345;

105! k=1;

106

107 alpha=2;

107! lambda=2;

108

109

110 n=10;

110! m=n;

110! R=J(m,1,0);

111

112 print alpha lambda;

113

114

115

116 W=J(m,1,0);

116! V=J(m,1,0);

116! X_p=J(m,1,0);

116! X_A=J(m,1,0);

116! U=J(m,1,0);

117

118 X=J(m,1,0);

119

120 do i=1 to m;

121 W[i]=Uniform(seed);

122 end;

123

124 S=1+R[m];

125 V[1]=W[1]**(1/S);

126

127 do i=2 to m;

128 S=S+(1+R[m-i+1]);

129 V[i]=W[i]**(1/S);

130 end;

131

132 do i=1 to m;

133

134 U[i]=1-prod( V[ m:( m-i+1)] );

134! ** the U's are the required progressively type II from U(0,1);

135

136 END;

137

138

139 X=( 1-(1-U)##(1/alpha) )##(1/lambda);

140

141

142 *******************************************************************************;

143 *** MLE for the Kumaraswamy using Type II Adaptive progressive censoring ***** ;

144 *******************************************************************************;

145

146 start MLE_func(y) global (n,m,X,R);

147

148 func=0;

149

150 alpha=y[1];

151 lambda=y[2];

152

153

154 Sum_log=J(m,1,0);

155 Sum_log=log(x);

156

157 Sum_log_1=J(m,1,0);

158 Sum_log_1=log(1-X##lambda);

159

160

161 func=func + m*log(alpha*lambda)+(lambda-1)* Sum_log[+] + (alpha-1) * Sum_log_1[+] ;

162

163 Return(func);

164

165 finish;

NOTE: Module MLE_FUNC defined.

166

167

168

169

170 ************* Constrain MLE ***********************;

171

172 con={0.01 0.01 , . .};

173 x0={0.05, 0.05};

174 tc={10000 14000};

175

176 *************** MLE *********************;

177

178

179 call nlpnra(rc, MLE_ret, "MLE_func", x0, opt, con,tc);

ERROR: (execution) Matrix has not been set to a value.

operation : NLPNRA at line 179 column 1

operands : *LIT1049, x0, opt, con, tc

*LIT1049 1 row 1 col (character, size 😎

MLE_func

x0 2 rows 1 col (numeric)

0.05

0.05

opt 0 row 0 col (type ?, size 0)

con 2 rows 2 cols (numeric)

0.01 0.01

. .

tc 1 row 2 cols (numeric)

10000 14000

statement : CALL at line 179 column 1

180

181 alpha_mle =MLE_ret[1];

ERROR: (execution) Matrix has not been set to a value.

operation : [ at line 181 column 19

operands : MLE_ret, *LIT1050

MLE_ret 0 row 0 col (type ?, size 0)

*LIT1050 1 row 1 col (numeric)

1

statement : ASSIGN at line 181 column 1

182 lambda_mle=MLE_ret[2];

ERROR: (execution) Matrix has not been set to a value.

operation : [ at line 182 column 19

operands : MLE_ret, *LIT1051

MLE_ret 0 row 0 col (type ?, size 0)

*LIT1051 1 row 1 col (numeric)

2

statement : ASSIGN at line 182 column 1

183

184

185 print alpha_mle lambda_mle;

ERROR: Matrix alpha_mle has not been set to a value.

statement : PRINT at line 185 column 1

186

187

188

189

190 quit;

NOTE: Exiting IML.

NOTE: The SAS System stopped processing this step because of errors.

NOTE: PROCEDURE IML used (Total process time):

real time 0.08 seconds

cpu time 0.03 seconds

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The log file tells you exactly what is wrong: You are using the variable OPT but you have not set it to a value:

179 call nlpnra(rc, MLE_ret, "MLE_func", x0, opt, con,tc);

ERROR: (execution) Matrix has not been set to a value.

operation : NLPNRA at line 179 column 1

operands : *LIT1049, x0, opt, con, tc

**opt 0 row 0 col (type ?, size 0)**

In general, search the log for the FIRST error. Fix that error. Then re-run and repeat the process until there are no errors.

You might also want to read the article, "Ten tips before you run an optimization."

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

It seems that I sent the old log file. The error due to opt was fixed. The error which I am referring to it is the one below.

Moreover, You suggested to me to use the procedure in the https://blogs.sas.com/content/iml/2018/02/28/solve-system-nonlinear-equations-sas.html

does that mean that the one that I am using in my code is not correct or may not work in my case?

Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The third paragraph of that article says

**In SAS/ETS software, you can use the SOLVE statement in PROC MODEL to solve the system**

so, yes, you can do it that way. It is not as efficient as solving the system in SAS/IML, but it'll work.

I suggest that you debug the PROC MODEL statement outside of the SUBMIT block and the IML loop. That is what is causing the errors. Your second equation is

eq.Xsqr = Xsqr/**n**-alpha1*gamma(alpha1)*gamma(2/lambda1+1)/gamma(alpha1+2/lambda1+1);

and the error message is telling you that n has not been defined.

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.