SAS multidimensional loop

kmon

New Member
#1
I am trying to compute using two loops. But I am not very familiar with loop elements.

Here is my data:

data try;
input rs t a b c;
datalines;
0 600
1 600 0.02514 667.53437 0.1638
2 600 0.2766 724.60233 0.30162
3 610 0.01592 792.34628 0.21354
4 615.2869 0.03027 718.30377 0.22097
5 636.0273 0.01967 705.45965 0.16847
;
run;
What I am trying to compute is that for each 'T' value, all elements of a, b, and c need to be used for the equation. Then I create varaibles v1-v6 to put results of the equation for each T1-T6. After that, I create CS to sum all the elements of v.

So my result dataset will look like this:

rs T a b c v1 v2 v3 v4 v5 v6 CS
0 600 sum of v1
1 600 0.02514 667.53437 0.1638 sum of v2
2 600 0.2766 724.60233 0.30162 sum of v3
3 610 0.01592 792.34628 0.21354 sum of v4
4 615.2869 0.03027 718.30377 0.22097 sum of v5
5 636.0273 0.01967 705.45965 0.16847 sum of v6
I wrote a code below to do this but got errors. Mainly I am not sure how to use i and j properly to link all elements of variables. Can someone point out what i did not think correct? I am aware that myabe I should not use sum function to cum up elements of a variable but not sure which function to use.

data try3;
set try;
retain v1-v6;
retain t a b c;
array v(*) v1-v6;
array var(*) t a b c;
cs=0;
do i=1 to 6;
do j=1 to 6;
v[i,j]=(2.89*(a[j]**2*(1-c[j]))/
((c[j]+exp(1.7*a[j]*(t-b[j])))*
((1+exp(-1.7*a[j]*(t-b[j])))**2));
cs=sum(of v[i,j]-v[i,j]);
end;
end;
run;

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

Forexample, v1 will be computed like v[1,1] =0 because there is no values for a b c.

For v[1,2]=(2.89*0.02514**2(1-0.1638))/((0.1638+exp(1.7*0.02514*600-667.53437)))*((1+exp(-1.7*0.02514*(600-667.5347)))**2)).

v[1,3]]=(2.89*0.2766**2(1-0.30162))/((0.30162+exp(1.7*0.2766*600-724.60233)))*((1+exp(-1.7*0.2766*(600-724.60233)))**2)).

v[1,4] will be using the next line values of a b c but the t will be same as the t[1]. and do this until the last row. And that will be v1. And then I need to sum all the elements of v1 like v1{1,1] +v1[1,2]+ v1{1,3] ....v1[1,6] to make cs[1,1].
 
#2
Dear All, I am doing statistic with sas and want to confirm that my command specially Random comand and want to confirm is it correctelly anylysed and the second thing to do labelling Least Squares Means which process i can follow at the moment there are only 3 variables so it is easy to label manually but if i found interaction significant than the Least Squares Means diff list goes long and it become difficult for me to do manually is there any solotion.

Thanks


data HHPFMm;
input Plough$ Brsica$ block$ cultr$ HHPFMm1;
cards;
Sp Rs 1 P+O 0.681
Sp Rs 2 P+O 0.239
Sp Sa 2 P+O 0.672
Sp Sa 1 P+O 0.758
Sp Bj 1 P+O 1.238
Sp Bj 2 P+O 0.592
Dp Sa 1 P+O 0.754
Dp Sa 2 P+O 1.046
Dp Rs 2 P+O 0.764
Dp Rs 1 P+O 0.764
Dp Bj 1 P+O 0.797
Dp Bj 2 P+O 1.129
Sp Rs 3 P+O 1.144
Sp Rs 4 P+O 0.927
Sp Bj 4 P+O 1.289
Sp Bj 3 P+O 0.639
Sp Sa 3 P+O 0.876
Sp Sa 4 P+O 0.979
Dp Bj 4 P+O 0.971
Dp Bj 3 P+O 1.026
Dp Sa 3 P+O 0.759
Dp Sa 4 P+O 1.15
Dp Rs 4 P+O 0.704
Dp Rs 3 P+O 1.169
Sp Rs 1 P 1.652
Sp Rs 2 P 1.239
Sp Sa 2 P 0.381
Sp Sa 1 P 0.869
Sp Bj 1 P 1.277
Sp Bj 2 P 0.641
Dp Sa 1 P 0.973
Dp Sa 2 P 1.523
Dp Rs 2 P 1.261
Dp Rs 1 P 1.443
Dp Bj 1 P 1.052
Dp Bj 2 P 1.56
Sp Rs 3 P 1.673
Sp Rs 4 P 1.222
Sp Bj 4 P 1.074
Sp Bj 3 P 1.916
Sp Sa 3 P 1.775
Sp Sa 4 P 1.077
Dp Bj 4 P 1.461
Dp Bj 3 P 1.317
Dp Sa 3 P 1.24
Dp Sa 4 P 1.052
Dp Rs 4 P 0.983
Dp Rs 3 P 1.155
;;
proc mixed data=HHPFMm;
class block Plough Brsica cultr;
model HHPFMm1=block Plough
Brsica Plough*Brsica
cultr Plough*cultr Brsica*cultr Plough*Brsica*cultr;
random block*Plough block*Plough*Brsica;
lsmeans cultr/pdiff adjust=tukey;
run;
Normally distributed 20:57 Sunday, March 25, 2012 15

The Mixed Procedure

Model Information

Data Set WORK.HHPFMM
Dependent Variable HHPFMm1
Covariance Structure Variance Components
Estimation Method REML
Residual Variance Method Profile
Fixed Effects SE Method Model-Based
Degrees of Freedom Method Containment


Class Level Information

Class Levels Values

block 4 1 2 3 4
Plough 2 Dp Sp
Brsica 3 Bj Rs Sa
cultr 2 P P+O



Dimensions

Covariance Parameters 3
Columns in X 40
Columns in Z 32
Subjects 1
Max Obs Per Subject 48


Number of Observations

Number of Observations Read 48
Number of Observations Used 48
Number of Observations Not Used 0


Iteration History

Iteration Evaluations -2 Res Log Like Criterion

0 1 38.75526819
1 2 31.50026176 0.00007742
2 1 31.49909487 0.00000022
3 1 31.49909164 0.00000000


Convergence criteria met.

Normality 20:57 Sunday, March 25, 2012 16

The Mixed Procedure

Covariance Parameter Estimates

Cov Parm Estimate

block*Plough 0.05583
block*Plough*Brsica 0
Residual 0.06478


Fit Statistics

-2 Res Log Likelihood 31.5
AIC (smaller is better) 35.5
AICC (smaller is better) 35.9
BIC (smaller is better) 35.7


Type 3 Tests of Fixed Effects

Num Den
Effect DF DF F Value Pr > F

block 3 3 0.48 0.7186
Plough 1 3 0.08 0.7982
Brsica 2 12 1.06 0.3764
Plough*Brsica 2 12 0.69 0.5188
cultr 1 18 24.62 0.0001
Plough*cultr 1 18 0.19 0.6655
Brsica*cultr 2 18 1.39 0.2756
Plough*Brsica*cultr 2 18 0.87 0.4361


Least Squares Means

Standard
Effect cultr Estimate Error DF t Value Pr > |t|

cultr P 1.2423 0.09837 18 12.63 <.0001
cultr P+O 0.8778 0.09837 18 8.92 <.0001


Differences of Least Squares Means

Standard
Effect cultr _cultr Estimate Error DF t Value Pr > |t| Adjustment Adj P

cultr P P+O 0.3645 0.07347 18 4.96 0.0001 Tukey-Kramer 0.0001