LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2004, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 7 Jul 2004 12:23:51 +0200
Reply-To:     "Groeneveld, Jim" <jim.groeneveld@VITATRON.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Groeneveld, Jim" <jim.groeneveld@VITATRON.COM>
Subject:      Re: Output Questions
Comments: To: schmitta@UWM.EDU
Content-Type: text/plain; charset="iso-8859-1"

Hi Thomas,

That is not a question, that is a complete project. Try to extract the most essential part of your problem in just a few lines of representative example code. Only in that case you might expect to get suggestions, which you may apply to your code in question.

I don't have and don't know about PROC IML, but I can immediately point to some strange or inefficient parts in your code. But answering you questions would take a lot more time:

1. As a good habit end every data step with a RUN statement.

2. Change DATA inf; SET paramet; into: DATA table (DROP = item b a c mthe minf); SET paramet; and remove the inefficient, redundant data step: DATA table; SET inf (DROP = item b a c mthe minf);

3. I think you lines of code: if corr_fac2 > .001 then goto iteration; else if corr_fac2 < -.001 then goto iteration; may be different from intended, as only if corr_fac2 = -.001 the goto is not done. (Is it usual in PROC IML to use the GOTO construct that frequently?)

4. Quite some code should be replaced by repeating macro code in a macro.

5. The RUN and QUIT statemtents after the OPTIONS statements do not seem in their right place.

No start limiting the code to what you really want to ask about it.

Regards - Jim. -- . . . . . . . . . . . . . . . .

Jim Groeneveld, MSc. Biostatistician Science Team Vitatron B.V. Meander 1051 6825 MJ Arnhem Tel: +31/0 26 376 7365 Fax: +31/0 26 376 7305 Jim.Groeneveld@Vitatron.com www.vitatron.com

My statistics are quite predictable, but my computer may be quite unpredictable.

[common disclaimer]

-----Original Message----- From: Thomas A. Schmitt [mailto:schmitta@UWM.EDU] Sent: Tuesday, July 06, 2004 19:33 To: SAS-L@LISTSERV.UGA.EDU Subject: Output Questions

Hi All,

I've pasted a simulation program I've written below. I have a few questions. First, near the end of the program I'm outputting "responses" for the CAT loop. I would like it to output each response for a 20-item CAT for a specified number of tests. Also, I would like each test to be copied 2 times. So, below there is two tests each copied twice. I would like to do this for each examinee in the simulation. Also, for the "theta" output file if anyone can figure out why there is a space between each of the "t" loops that would be great. I can't understand why that file is doing it and not the others. Also, if anyone needs the data file just let me know. Thanks,

Tom

11000011010011101001 11000011010011101001 11000011010011101001 00100111101010001110 00100111101010001110 00100111101010001110

OPTIONS NODATE NONOTES;

DATA paramet; INFILE 'C:\Documents and Settings\Thomas A. Schmitt\Desktop\data'; INPUT item b a c; DATA inf; SET paramet; mthe = (b + (1/(1.7*a))*log(0.5+(0.5*sqrt(1+8*c)))); minf = ((2.89*a**2)/(8*(1-c)**2))*((1-20*c-8*c**2)+(1+8*c)**(3/2)); if mthe ge -3.00000 and mthe lt -2.57143 then minf01 = minf; else if mthe ge -2.57143 and mthe lt -2.14286 then minf02 = minf; else if mthe ge -2.14286 and mthe lt -1.71429 then minf03 = minf; else if mthe ge -1.71429 and mthe lt -1.28571 then minf04 = minf; else if mthe ge -1.28571 and mthe lt -0.85714 then minf05 = minf; else if mthe ge -0.85714 and mthe lt -0.42857 then minf06 = minf; else if mthe ge -0.42857 and mthe lt 0.00000 then minf07 = minf; else if mthe ge 0.00000 and mthe lt 0.42857 then minf08 = minf; else if mthe ge 0.42857 and mthe lt 0.85714 then minf09 = minf; else if mthe ge 0.85714 and mthe lt 1.28571 then minf10 = minf; else if mthe ge 1.28571 and mthe lt 1.71429 then minf11 = minf; else if mthe ge 1.71429 and mthe lt 2.14286 then minf12 = minf; else if mthe ge 2.14286 and mthe lt 2.57143 then minf13 = minf; else if mthe ge 2.57143 and mthe lt 3.00000 then minf14 = minf;

DATA table; SET inf (DROP = item b a c mthe minf);

PROC IML; USE table; READ all into infmatrix; DO i = 1 to 2; DO t = 1 to 14; FREE parmatrx; FREE prob_mat; FREE prob2_mat FREE q_mat; FREE q2_mat FREE chance_mat; FREE der1_mat; FREE dder1_mat; FREE der2_mat; FREE dder2_mat; FREE response_mat; FREE col_mat; FREE row_mat; FREE thnew_mat; FREE response_mat; FREE prob2_mat; FREE der2_mat; FREE dder2_mat; FREE q2; Free Iinf_mat; seed = 0; total = nrow(infmatrix); num_right = 0; num_wrong = 0; col = 8;

if t = 1 then theta = ranuni(seed) * (0.42857) - 3.00000; else if t = 2 then theta = ranuni(seed) * (0.42857) - 2.57143; else if t = 3 then theta = ranuni(seed) * (0.42857) - 2.14286; else if t = 4 then theta = ranuni(seed) * (0.42857) - 1.71429; else if t = 5 then theta = ranuni(seed) * (0.42857) - 1.28571; else if t = 6 then theta = ranuni(seed) * (0.42857) - 0.85714; else if t = 7 then theta = ranuni(seed) * (0.42857) - 0.42857;

else if t = 8 then theta = ranuni(seed) * (0.42857) + 0.00000;

else if t = 9 then theta = ranuni(seed) * (-0.42857) + 0.85714; else if t = 10 then theta = ranuni(seed) * (-0.42857) + 1.28571; else if t = 11 then theta = ranuni(seed) * (-0.42857) + 1.71429; else if t = 12 then theta = ranuni(seed) * (-0.42857) + 2.14286; else if t = 13 then theta = ranuni(seed) * (-0.42857) + 2.57143; else if t = 14 then theta = ranuni(seed) * (-0.42857) + 3.00000;

DO CAT = 1 to 20; done = 0; DO until (done=1); row=int(ranuni(seed)*total); if row = 0 then row = row +1; if infmatrix[row,col] ^= . then done = 1; test = infmatrix[row,col]; END; row_mat=row_mat//row; col_mat=col_mat//col; test_mat=test_mat//test; USE paramet; read point row into matrx; abc=matrx[1,3] || matrx[1,2] || matrx[1,4]; mattrib parmatrx colname=({a b c}); if (CAT=1) then DO; parmatrx=abc; END; else DO; parmatrx=parmatrx//abc; END; PRINT parmatrx; prob=parmatrx[,3]+((1-parmatrx[,3])/ (1+exp(-1.7#parmatrx[,1]#(theta-parmatrx[,2])))); prob_mat=prob_mat//prob[CAT,]; chance = ranuni(seed); chance_mat=chance_mat//chance; q = 1-prob[CAT,]; q_mat=q_mat//q; if prob_mat[CAT,] >= chance_mat[CAT,] then response=1; else if prob_mat[CAT,] <= chance_mat[CAT,] then response=0; response_mat=response_mat//response; if prob_mat[CAT,] >= chance_mat[CAT,] then num_right=num_right+1; else if prob_mat[CAT,] <= chance_mat[CAT,] then num_wrong=num_wrong+1; iteration_count = 0; iteration: FREE q2_mat; FREE der2_mat; FREE dder2_mat; FREE d2_mat; FREE dd2_mat; FREE prob2_mat; FREE der2_sum_mat; FREE dder2_sum_mat; if (num_right < 1) | (num_wrong < 1) then GOTO skip1; DO it = 1 to CAT; if theta_new < -4.00000 then theta_new=-4.00000; else if theta_new > 4.00000 then theta_new=4.00000; prob2=parmatrx[,3]+((1-parmatrx[,3])/ (1+exp(-1.7#parmatrx[it,1]#(theta_new-parmatrx[,2])))); prob2_mat=prob2_mat//prob2[it,]; q2 = 1-prob2_mat[it,]; q2_mat=q2_mat//q2;

der2=(parmatrx[,1]#(response_mat[it,]-prob2_mat[it,])#(prob2_mat[it,]- parmatrx[,3]))/(prob2_mat[it,]#(1-parmatrx[,3])); dder2=((parmatrx[,1]##2)#(prob2_mat[it,]-parmatrx[,3])#q2_mat[it,])/

((1-parmatrx[,3])##2#prob2_mat[it,])#(((response_mat[it,]#parmatrx[,3])/ prob2_mat[it,])-prob2_mat[it,]); der2_mat=der2_mat//der2[it,]; dder2_mat=dder2_mat//dder2[it,]; der2_sum=der2_mat [+,]; der2_sum_mat=der2_sum_mat//der2_sum; dder2_sum=dder2_mat [+,]; dder2_sum_mat=dder2_sum_mat//dder2_sum; if dder2_sum_mat = 0 then goto skip1; d2=der2_sum*1.7; d2_mat=d2_mat//d2; dd2=dder2_sum*2.89; dd2_mat=dd2_mat//dd2; if it = CAT then DO; corr_fac2=d2_mat[it,]/dd2_mat[it,]; theta_new=theta_new-corr_fac2; if theta_new < -3.00000 then theta_new=-3.00000; else if theta_new > 3.00000 then theta_new=3.00000; if it=CAT then iteration_count=iteration_count+1; if iteration_count=10 then goto skip1; if corr_fac2 > .001 then goto iteration; else if corr_fac2 < -.001 then goto iteration; end; end; skip1: if (num_right >=1) & (num_wrong >=1) then goto skip2; if prob_mat[CAT,] >= chance_mat[CAT,] then col=col+10; else if prob_mat[CAT,] <= chance_mat[CAT,] then col=col-10; if col < 0 then col = 1; else if col > 14 then col = 14; if col < 1 then col = 1; else if col > 14 then col = 14; if t = 1 then theta_new = ranuni(seed) * (0.42857) - 3.00000; else if t = 2 then theta_new = ranuni(seed) * (0.42857) - 2.57143; else if t = 3 then theta_new = ranuni(seed) * (0.42857) - 2.14286; else if t = 4 then theta_new = ranuni(seed) * (0.42857) - 1.71429; else if t = 5 then theta_new = ranuni(seed) * (0.42857) - 1.28571; else if t = 6 then theta_new = ranuni(seed) * (0.42857) - 0.85714; else if t = 7 then theta_new = ranuni(seed) * (0.42857) - 0.42857;

else if t = 8 then theta_new = ranuni(seed) * (0.42857) + 0.00000;

else if t = 9 then theta_new = ranuni(seed) * (-0.42857) + 0.85714; else if t = 10 then theta_new = ranuni(seed) * (-0.42857) + 1.28571; else if t = 11 then theta_new = ranuni(seed) * (-0.42857) + 1.71429; else if t = 12 then theta_new = ranuni(seed) * (-0.42857) + 2.14286; else if t = 13 then theta_new = ranuni(seed) * (-0.42857) + 2.57143; else if t = 14 then theta_new = ranuni(seed) * (-0.42857) + 3.00000; if (num_right < 1) | (num_wrong < 1) then goto skip3; skip2: if theta_new < -3.00000 then col = 1; else if theta_new >= -3.00000 & theta_new < -2.57143 then col = 1; else if theta_new >= -2.57143 & theta_new < -2.14286 then col = 2; else if theta_new >= -2.14286 & theta_new < -1.71429 then col = 3; else if theta_new >= -1.71429 & theta_new < -1.28571 then col = 4; else if theta_new >= -1.28571 & theta_new < -0.85714 then col = 5; else if theta_new >= -0.85714 & theta_new < -0.42857 then col = 6;

else if theta_new >= -0.42857 & theta_new < 0.00000 then col = 7;

else if theta_new >= 0.00000 & theta_new < 0.42857 then col = 8; else if theta_new >= 0.42857 & theta_new < 0.85714 then col = 9; else if theta_new >= 0.85714 & theta_new < 1.28571 then col = 10; else if theta_new >= 1.28571 & theta_new < 1.71429 then col = 11; else if theta_new >= 1.71429 & theta_new < 2.14286 then col = 12; else if theta_new >= 2.14286 & theta_new < 2.57143 then col = 13; else if theta_new >= 2.57143 & theta_new < 3.00000 then col = 14; else if theta_new > 3.00000 then col = 14; skip3: file 'C:\resp.doc'; if CAT = 1 then put @1 response @; else if CAT = 2 then put @2 response @; else if CAT = 3 then put @3 response @; else if CAT = 4 then put @4 response @; else if CAT = 5 then put @5 response @; else if CAT = 6 then put @6 response @; else if CAT = 7 then put @7 response @; else if CAT = 8 then put @8 response @; else if CAT = 9 then put @9 response @; else if CAT = 10 then put @10 response @; else if CAT = 11 then put @11 response @; else if CAT = 12 then put @12 response @; else if CAT = 13 then put @13 response @; else if CAT = 14 then put @14 response @; else if CAT = 15 then put @15 response @; else if CAT = 16 then put @16 response @; else if CAT = 17 then put @17 response @; else if CAT = 18 then put @18 response @; else if CAT = 19 then put @19 response @; else if CAT = 20 then put @20 response @; end; put; PRINT theta_new; theta_final = theta_new; PRINT theta; PRINT theta_final; Iinf = (2.89#parmatrx[,1]##2#(1-parmatrx[,3]))/

((parmatrx[,3]+2.718##(1.7#parmatrx[,1]#(theta_new-parmatrx[,2])))# (1+2.718##(-1.7#parmatrx[,1]#(theta_new-parmatrx[,2])))##2); Iinf_mat=Iinf_mat//Iinf; Iinf_sum=Iinf_mat [+,]; PRINT Iinf_mat; PRINT Iinf_sum; std_er = 1/sqrt(Iinf_sum); PRINT std_er; file 'C:\theta_new'; if t = 1 then put @1 theta_new @; else if t = 2 then put @11 theta_new @; else if t = 3 then put @21 theta_new @; else if t = 4 then put @31 theta_new @; else if t = 5 then put @41 theta_new @; else if t = 6 then put @51 theta_new @; else if t = 7 then put @61 theta_new; else if t = 8 then put @1 theta_new @; else if t = 9 then put @11 theta_new @; else if t = 10 then put @21 theta_new @; else if t = 11 then put @31 theta_new @; else if t = 12 then put @41 theta_new @; else if t = 13 then put @51 theta_new @; else if t = 14 then put @61 theta_new;

file 'C:\std_er'; if t = 1 then put @1 std_er @; else if t = 2 then put @11 std_er @; else if t = 3 then put @21 std_er @; else if t = 4 then put @31 std_er @; else if t = 5 then put @41 std_er @; else if t = 6 then put @51 std_er @; else if t = 7 then put @61 std_er; else if t = 8 then put @1 std_er @; else if t = 9 then put @11 std_er @; else if t = 10 then put @21 std_er @; else if t = 11 then put @31 std_er @; else if t = 12 then put @41 std_er @; else if t = 13 then put @51 std_er @; else if t = 14 then put @61 std_er;

file 'C:\theta'; if t = 1 then put @1 theta @; else if t = 2 then put @11 theta @; else if t = 3 then put @21 theta @; else if t = 4 then put @31 theta @; else if t = 5 then put @41 theta @; else if t = 6 then put @51 theta @; else if t = 7 then put @61 theta; else if t = 8 then put @1 theta @; else if t = 9 then put @11 theta @; else if t = 10 then put @21 theta @; else if t = 11 then put @31 theta @; else if t = 12 then put @41 theta @; else if t = 13 then put @51 theta @; else if t = 14 then put @61 theta; end; put; end; PRINT response_mat; options notes; run; quit;


Back to: Top of message | Previous page | Main SAS-L page