BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
karen8169
Obsidian | Level 7
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.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

5 REPLIES 5
Reeza
Super User

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. 

PGStats
Opal | Level 21

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
karen8169
Obsidian | Level 7

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

PGStats
Opal | Level 21

To change the color of markers, add the statement

 

styleattrs datacontrastcolors=(black yellow);

 

to proc sgplot.

PG
Rick_SAS
SAS Super FREQ

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..

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 645 views
  • 3 likes
  • 4 in conversation