correct graphics program

Accepted Solution Solved
Reply
Contributor
Posts: 39
Accepted Solution

correct graphics program

Data MCint;
seed1=12345;
do isim=1 to 100000;
Ux=ranuni(seed1);
Uy=ranuni(seed1);
Under = (Uy<=sqrt(1-Ux**2));
drop isim;
output;
end;

ODS OUTPUT OneWayFreqs=data_freq;
proc freq;
table Under;
run;
ODS OUTPUT CLOSE;

proc print data =data_freq;run;
data summary; set data_freq;
if under=1;
PI_est=4*Percent/100;
prop_est=Percent/100;
SE_PI_EST=4*sqrt(prop_est*(1-pop_est)/10000);
PI_CI_Low=PI_est-2*SE_PI_EST;
PI_CI_Up=PI_est-2*SE_PI_EST;
put ' ------------------------------------------';
put ' | MC Integration estimate of PI        |';
put ' ------------------------------------------';
put ' PI(estimate)=' PI_est;
put ' SE[PI(estimate)]=' SE_PI_EST;
put ' Approx. 95% CI=' PI_CI_Low' ,' PI_CI_Up;
put ' ' ;
put ' Based on 10,000 simulated points.' ;
put ' ------------------------------------------' ;
run;

ODS RTF file= ' C:\SAS-programs\MC-fig.rtf';
proc gplot data=MCint;
  plot Uy*Ux=Under ;
  ods graphics / reset width=50px height=300px;
  symbol1 value=dot color=black;
  symbol2 value=dot color=yellow;
  run;
ODS RTF CLOSE;

I have few queestion.

First, why the lines after 'put' don't appear?

Secon, how should I control the graph size?  It seems that I can't perfectly graph square by chnging the width and height.

Finally, I want to mark the coordinate with cross rather than dot but I can't control it by rewriting cross.


Accepted Solutions
Solution
‎11-24-2016 01:43 AM
Respected Advisor
Posts: 4,606

Re: correct graphics program

The data _null_ step still needs some tweaking, but it should be something like:

 

Data MCint;
call streaminit(12345);
do isim=1 to 10000;
    Ux = rand("UNIFORM");
    Uy = rand("UNIFORM");
    Under = (Uy<=sqrt(1-Ux**2));
    drop isim;
    output;
    end;
run;

ODS OUTPUT OneWayFreqs=data_freq;
proc freq;
table Under;
run;

proc print data =data_freq;run;

data _null_; 
set data_freq;
if under=1;
PI_est=4*Percent/100;
prop_est=Percent/100;
SE_PI_EST=4*sqrt(prop_est*(1-pop_est)/10000);
PI_CI_Low=PI_est-2*SE_PI_EST;
PI_CI_Up=PI_est-2*SE_PI_EST;
file print;
put ' ------------------------------------------';
put ' | MC Integration estimate of PI          |';
put ' ------------------------------------------';
put ' PI(estimate)=' PI_est;
put ' SE[PI(estimate)]=' SE_PI_EST;
put ' Approx. 95% CI=' PI_CI_Low' ,' PI_CI_Up;
put ' ' ;
put ' Based on 10,000 simulated points.' ;
put ' ------------------------------------------' ;
run;

ods graphics / imagename="Circle" antialiasmax=11000;
proc sgplot data=MCint aspect=1;
scatter x=Ux y=Uy / group=Under markerattrs=(symbol=Plus size=5);
xaxis min=0 max=1;
yaxis min=0 max=1;
run;

Circle.png

 

 

PG

View solution in original post


All Replies
Grand Advisor
Posts: 17,325

Re: correct graphics program

Couple of issues. 

 

Don't include the ODS OUTPUT CLOSE statement. I'm not sure what you're expecting but it's unnecessary and can cause issues later on.  

 

PUT outputs to the log, so check if the log has the information you're desiring. If that's not the functionality you want, clarify please. 

 

SAS/Graph procs such as GPLOT Don't use ODS graphics options. And your ODS graphics options would have to be BEFORE the proc , order of operations issue. 

 

I would recommend switching to SGPLOT for more functionality. 

Place your ODS graphics statement before the proc. symbol statements work with GPlot but you need different statements for SGPLOT - see the docs. 

 

If you need further help please post back. 

Solution
‎11-24-2016 01:43 AM
Respected Advisor
Posts: 4,606

Re: correct graphics program

The data _null_ step still needs some tweaking, but it should be something like:

 

Data MCint;
call streaminit(12345);
do isim=1 to 10000;
    Ux = rand("UNIFORM");
    Uy = rand("UNIFORM");
    Under = (Uy<=sqrt(1-Ux**2));
    drop isim;
    output;
    end;
run;

ODS OUTPUT OneWayFreqs=data_freq;
proc freq;
table Under;
run;

proc print data =data_freq;run;

data _null_; 
set data_freq;
if under=1;
PI_est=4*Percent/100;
prop_est=Percent/100;
SE_PI_EST=4*sqrt(prop_est*(1-pop_est)/10000);
PI_CI_Low=PI_est-2*SE_PI_EST;
PI_CI_Up=PI_est-2*SE_PI_EST;
file print;
put ' ------------------------------------------';
put ' | MC Integration estimate of PI          |';
put ' ------------------------------------------';
put ' PI(estimate)=' PI_est;
put ' SE[PI(estimate)]=' SE_PI_EST;
put ' Approx. 95% CI=' PI_CI_Low' ,' PI_CI_Up;
put ' ' ;
put ' Based on 10,000 simulated points.' ;
put ' ------------------------------------------' ;
run;

ods graphics / imagename="Circle" antialiasmax=11000;
proc sgplot data=MCint aspect=1;
scatter x=Ux y=Uy / group=Under markerattrs=(symbol=Plus size=5);
xaxis min=0 max=1;
yaxis min=0 max=1;
run;

Circle.png

 

 

PG
Contributor
Posts: 39

Re: correct graphics program

How can I change the color as the previous picture I made?

Respected Advisor
Posts: 4,606

Re: correct graphics program

To change the color of markers, add the statement

 

styleattrs datacontrastcolors=(black yellow);

 

to proc sgplot.

PG
SAS Super FREQ
Posts: 3,406

Re: correct graphics program

You might be interested in reading the article "Monte Carlo estimates of pi."

 

BTW, you can use the OUT= option on the TABLES statement in PROC FREQ. Then you can suppress output by using the NOPRINT option on the PROC FREQ stmt. You don't need to use ODS output..

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 228 views
  • 3 likes
  • 4 in conversation