Demo entry 6646702

SAS

   

Submitted by anonymous on Oct 18, 2017 at 03:39
Language: SAS. Code size: 4.3 kB.

%macro a(seed= ); /*创建n=30个人的生日的宏8*/                                                                                            
data birth;                                                                                                                             
array b{30}b1-b30;                                                                                                                      
do i=1 to 30;                                                                                                                           
b{i}=ceil(uniform(&seed)*365);                                                                                                          
end;                                                                                                                                    
flag=0;                                                                                                                                 
do k=1 to 29;                                                                                                                           
  do m=k+1 to 30;                                                                                                                       
  if b{k}=b{m}                                                                                                                          
     then flag=1;                                                                                                                       
  if flag=1                                                                                                                             
     then leave;                                                                                                                        
   end;                                                                                                                                 
if flag=1 then leave;                                                                                                                   
end;                                                                                                                                    
put flag;                                                                                                                               
run;                                                                                                                                    
%mend a;                                                                                                                                
                                                                                                                                        
%macro outer;   /*将产生30个人生日的宏模拟500次*/                                                                                       
%do i=1 %to 500;                                                                                                                        
%a(seed=&i);                                                                                                                            
proc append base=work.data_sim;                                                                                                         
%end;                                                                                                                                   
%mend ;                                                                                                                                 
%outer                                                                                                                                  
run;                                                                                                                                    
                                                                                                                                        
proc univariate freq  data=data_sim ;     /*计算生日数相同的频率*/                                                                      
var flag;                                                                                                                               
run; 

This snippet took 0.02 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).