Programming the statistical procedures from SAS

sas macro language programing

Reply
Occasional Contributor
Posts: 18

sas macro language programing

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;

 

 

SAS Super FREQ
Posts: 3,547

Re: sas macro language programing

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.

Super User
Posts: 10,871

Re: sas macro language programing

You might also want to look at using

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

This lets you specify mean and standard deviation directly.

Ask a Question
Discussion stats
  • 2 replies
  • 236 views
  • 0 likes
  • 3 in conversation