Solved
Contributor
Posts: 31

# help with sas code

Hi,

I have code to find mean of cv_hat (coverage value) and cv_curl:

Data propns;
seed = 123475;
nr = 10000; nc = 12;
array x[20];
zstar = abs ( probit(0.025) );
ppop = 0.5;
do r = 1 to nr;
do c = 1 to nc;
x[c] = ranbin(seed, 1, ppop);
nh = sum(of x[*]);
phat = nh / nc;
se_phat = sqrt( phat * (1-phat) / nc);
pcurl = (nh + 2)/(nc + 4);
se_pcurl = sqrt( pcurl * (1-pcurl) / (nc+4) );
zhat = (phat - ppop)/se_phat;
zcurl = (pcurl - ppop)/se_pcurl;
if abs(zhat) <= zstar then cv_hat = 1;
else cv_hat = 0;
if abs(zcurl) <= zstar then cv_curl = 1;
else cv_curl = 0;
end;
output;
end;
keep phat se_phat pcurl se_pcurl zhat zcurl cv_hat cv_curl;
run;

PROC means data = propns n mean stderr;
var cv_hat cv_curl;
run;

That is code for nc=12. I need for : from 10 to 100. Therefore, i need 91 means for cv_hat and  cv_hat. Moreover, i need a graph

means|

|

|

|

|_______________

nc

Thank you

P.S. Please show me how change my code (how use loop)

|

|

Accepted Solutions
Solution
‎04-05-2016 08:19 AM
PROC Star
Posts: 2,363

## Re: help with sas code

Look at the legend option and statement, and at the axis statement.

All Replies
Super User
Posts: 23,726

## Re: help with sas code

Do you understand your current code? It appears to loop from 1 to nc=12 already.

Are you looking to change that loop from 10 to 100 instead?

Or add another loop to iterate everthing from 10 to 100?

If so, you can add another outer loop for the nc variable and then you can add a BY nc to your proc means.
PROC Star
Posts: 2,363

## Re: help with sas code

[ Edited ]

Like this?

``````data PROPNS;
array X[100];
SEED  = 123475;
NR    = 10000;
PPOP  = 0.5;
ZSTAR = abs ( probit(0.025) );
do NC = 10 to 100;
call missing (of X[*]);
do R = 1 to NR;
do C = 1 to NC;
X[C]    = ranbin(SEED, 1, PPOP);
NH      = sum(of X[*]);
PHAT    = NH / NC;
SE_PHAT = sqrt( PHAT * (1-PHAT) / NC);
PCURL   = (NH + 2)/(NC + 4);
SE_PCURL= sqrt( PCURL * (1-PCURL) / (NC+4) );
ZHAT    = divide(PHAT  - PPOP, SE_PHAT );
ZCURL   = divide(PCURL - PPOP, SE_PCURL);
CV_HAT  = (abs(ZHAT) <= ZSTAR );
CV_CURL = (abs(ZCURL) <= ZSTAR);
end;
output;
end;
end;
keep NC PHAT SE_PHAT PCURL SE_PCURL ZHAT ZCURL CV_HAT CV_CURL;
run;

proc means data = PROPNS n mean stderr nway;
class NC;
var CV_HAT CV_CURL;
output out=SUM mean= ;
run;

proc gplot data=SUM;
plot (CV_HAT CV_CURL)*NC/overlay;
run;
quit;``````
Contributor
Posts: 31

## Re: help with sas code

I got this. Thank you so much. Could you show me how label each line( red and blue) and it shows just CV_HAT, i believ should be CV_HAT, CV_CURL.

Thank you

Solution
‎04-05-2016 08:19 AM
PROC Star
Posts: 2,363