Set statement in macro

Accepted Solution Solved
Reply
Super Contributor
Posts: 297
Accepted Solution

Set statement in macro

Hi I want to use the have one data on top of the other so that I could find the mean. How to I correct this;

data p;

set par&p;

run;

In the following code;

%macro surv(iterations=);

%do p=1 %to &iterations;

data test&p;

seed = -1;

  alpha1 = 2.50;

  beta1 = 9.50;

  do i = 1 to 100;

   lambdaT = 0.082; *baseline hazard;

   lambdaC=0.400001;

   * gender=ranbin(0,1,0.5); /*ranbin(Seed_3,n,p);*/

      er=0.00+sqrt(0.00001)*rannor(0); *error dist N(0.00,0.00001);

    t = rand("WEIBULL", 1, lambdaT); * time of event;

    c = rand("WEIBULL", 1, lambdaC) ;* time of censoring;

    time = min(t, c);    * which came first?;

    censored = (c lt t);

      obs=(t lt c); * creating observation variable from censored when observeed obs=1;

      y= alpha1+beta1*t+ er;

    output;

  end;

run;

proc reg data=test&p;

model y=t;

ods output ParameterEstimates=Para&p;

run;

Data Par&p;

      Set para&p;

      Where Variable = "t";

      TrueTime= 9.50;

      Bias = Estimate - TrueTime;

      PercentBias = (Bias/TrueTime)*100;

      MSE = Bias**2 + StdErr**2;

      If (Estimate - 1.96*StdErr) le TrueTime le (Estimate + 1.96*StdErr) then CovTime = 1; Else CovTime = 0;/*covarage probabilty*/

Run;

data p;

set par&p;

run;

Proc Means Data = p NOPRINT;

      Var Estimate StdErr Bias PercentBias MSE CovTime;

      Output out = Time Mean = Estimate StdErr Bias PercentBias MSE CovTime;

run;

%end;

%mend surv;

%surv(iterations=2);

proc print data=p;

run;


Accepted Solutions
Solution
‎02-11-2013 09:26 PM
Super User
Super User
Posts: 6,500

Re: Set statement in macro

It is not clear what your question is.  If you want to concatenate the iterations into a single file then you might want to use PROC APPEND.

proc append base=p date=par&p force ;

run;

And move the PROC MEANS call to after the %END statement so that it will work on the full dataset P after all of the iterations.

You also might want to add a step before the %DO loop to remove or clear any existing work dataset named P.

View solution in original post


All Replies
Solution
‎02-11-2013 09:26 PM
Super User
Super User
Posts: 6,500

Re: Set statement in macro

It is not clear what your question is.  If you want to concatenate the iterations into a single file then you might want to use PROC APPEND.

proc append base=p date=par&p force ;

run;

And move the PROC MEANS call to after the %END statement so that it will work on the full dataset P after all of the iterations.

You also might want to add a step before the %DO loop to remove or clear any existing work dataset named P.

Super Contributor
Posts: 297

Re: Set statement in macro

Hi I did this;

data p;

set par1-par2;

run;

And it works well

Super User
Super User
Posts: 6,500

Re: Set statement in macro

That will work.

Move the %END statement before this data step (and the PROC MEANS step after it).

Change par1-par2 to par1-par&interations so that it honors the users choice in the macro call for how many iterations to perform.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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