Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- sas macro language programing

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-29-2015 11:56 PM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-30-2015 05:58 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-30-2015 10:29 AM

You might also want to look at using

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

This lets you specify mean and standard deviation directly.