/* Simulate from the uniform */ /* This creates a macro, which a function that can loop over multiple SAS procedures */ %macro clt(n=,sims=); * Define macro name and arguments; %do i = 1 %to &sims; * Start loop; data dat1; * Create data set that holds simulated data; do i=1 to &n; y = rand("Uniform")*4; * Draw from U[0,4]; output; end; drop i; run; proc means data=dat1 noprint; * Compute y_bar; var y; output out=ybar_temp mean=ybar; run; %if &sims = 1 %then %do; * Append y_bar to data set; data ybar_data; set ybar_temp; keep ybar; run; %end; %else %do; proc append base = ybar_data data = ybar_temp(keep=ybar) force; run; %end; %end; proc sgplot data=ybar_data; * Plot the histogram and density of all y_bars; histogram ybar; density ybar / type=kernel; run; %mend; /* Perform function with n=1000 and "sims" number of simulations */ %clt(n=250,sims=1);