BookmarkSubscribeRSS Feed
fatemeh
Quartz | Level 8

hello.

please look at my coding and correct my mistake.i want to generate 100 samples from a normal distribution with mean of 0 and standard deviation of 10 and  construct two 95% confidence intevals for the mean under assumption of known variance and unknown variance seperately  for each sample and mark thoes intervals that do not cover mean 0 ,by three stars***. i want to have 20 observations for this prosse.i want to use sas macro language.

 here is my coding:


data x;
input mean n std upcl lowcl alpha=alpha t0 z0 tu tl zu zl;
datalines;
run;

%macro mymac;
%let macvar=one;
%do j=1 to 20;
data one;
%do i=1 %to 100;
%let x=rannor(-1)*10+0;
%output;
label &x='';
%end;

%let dat=mycvar;
proc means data=&dat mean clm std n;
%run;


data two ;
set stat (drop =_TYPE_ _FREQ_);
alpha =.05;
t0=tinv(1-alpha/2,n-1);
z0=probit(1-alpha/2);
zu=mean+z0*(10)/sqrt(n);
zl=mean-z0*(10)/sqrt(n);
tu=mean+t0*std/sqrt(n);
tl=mean-t0*std/sqrt(n);
run;

%let lc=lc;
%let uc=uc;

%let b=&lc*&uc;

%let eval_b=%eval(&b);

%put &b is &eval_b;

%macro compare(b,0);
%if &b>0 %then %put label &x='***';
%else %if &b<0 %then %put label &x='';

%mend compare;
%compare(0,&b)

%end ;
%mend;

proc append base=x data=two;
run;

data print;
call execute('proc print data=mymac;run;');
run;

 

 

2 REPLIES 2
Rick_SAS
SAS Super FREQ

Before you proceed you might want to read a little bit about how to perform efficient simulation in SAS.

As a general rule, you should avoid using macro loops to "drive" the simulation of multiple samples.

See the article "Simulation in SAS: The slow way or the BY way."

 

If this is a classroom exercise and you are REQUIRED to use macro, then let us know. We can address your programming errors and give you hints without writing the program for you.

 

If this is not a classroom exercise, then this problem does not require any macro code.  The link I've provided includes SAS code that generates multiple samples. The example uses the uniform distribution, but can be easily modified to use the normal distribution.

ballardw
Super User

You might also want to look at using

x = rand('NORMAL', 1, 10);

This lets you specify mean and standard deviation directly.

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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1454 views
  • 0 likes
  • 3 in conversation