BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bigban777
Obsidian | Level 7

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)

|

|

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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

View solution in original post

4 REPLIES 4
Reeza
Super User
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.
ChrisNZ
Tourmaline | Level 20

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;
bigban777
Obsidian | Level 7

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

snap.PNG

ChrisNZ
Tourmaline | Level 20

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 979 views
  • 1 like
  • 3 in conversation