BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
desireatem
Pyrite | Level 9

Hello, I need the baseline covariates fro PHREG for each of the random sample with replacement. THis code does see to work well. The problem is with

baseline covariates=Pattern_&pt out=survs_&u survival= survival;.

NB: I need to run this within a macro because I have some matrices to compute. Or within a for loop.

CODE.

data neww;

seed=-1;

  alpha1 = 10;

  beta1 = 10;

  beta2=10;

  do i = 1 to 141;

  Age=40+(5)*rannor(1);

   lambdaT = 0.025; *baseline hazard;

   lambdaC= .03;  *heavy=0.15; *light=0.03;

   er=0+(0.01)*rannor(1);

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

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

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

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

  pibflr= alpha1 + beta1*t + beta2*Age +er;

    output;

  end;

run;

%let pt=pt;

%macro pat(patt=);

%do &pt=1 %to &patt;  /*** I NEED THE BASELINE COVARIATE FOR AGE=0, So for each data below new_1, new_2, I want the first to set the covariates=Pattern_1, covariates=Pattern_2*/

data Pattern_&pt;

age=0;

output;

run;

%end;

%mend pat;

%MACRO DO_BRANCH(replicates=);

%do u=1 %to &replicates;

proc surveyselect data=neww  method = urs sampsize = 141 OUTHITS

     reps=1 seed=1234100 out=new_&u;

run;

%pat(patt=20);

ods trace on /listing;

ods graphics on;

ods output ParameterEstimates=CPHH_&u;

proc phreg data=new_&u ;

model monset*obs(0)=age;

*baseline out=survs survival= survival;

baseline covariates=Pattern_&pt out=survs_&u survival= survival;  /* The issue is that SAS doesnot seem to understand that I want covariates=pattern_1 when running the data set new_1 and covariates=pattern_2 for new_2*/

run;

ods trace off;

%end;

%MEND DO_BRANCH;

%DO_BRANCH(replicates=20);

THIS CODE RUNS BUT NOT THE ABOVE. Below is what I want the macro to do for each case.

data Pattern;

Age=0;

output;

run;

ods trace on /listing;

ods graphics on;

ods output ParameterEstimates=CPHH;

proc phreg data=new ;

model monset*obs(0)=age;

baseline covariates=pattern out=survs survival= survival  ;

run;

ods trace off;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Does this do what you expect it do?

Test it %put &pt afterwards to see what it resolves to:

%let pt=pt;

This will create a set of pattern_1, pattern_2 datasets that are identical. Why? There is no point to this, simply have one pattern dataset.

%macro pat(patt=);

%do &pt=1 %to &patt;

data Pattern_&pt;

age=0;

output;

run;

%end;

%mend pat;

%MACRO DO_BRANCH(replicates=);

%do u=1 %to &replicates;

proc surveyselect data=neww  method = urs sampsize = 141 OUTHITS

     reps=1 samprate=1  seed=-1 out=new_&u;

run;

%pat(patt=2); /*this isn't needed, see the above comments regarding why*/

ods trace on /listing;

ods graphics on;

ods output ParameterEstimates=CPHH_&u;

proc phreg data=new_&u ;

model monset*obs(0)=age;

*baseline out=survs survival= survival;

baseline covariates=Pattern_&pt out=survs_&u survival= survival;  /* The issue is that SAS doesnot seem to understand that I want covariates=pattern_1 when running the data set new_1 and covariates=pattern_2 for new_2*/

/*Does macro variable &pt exist here, and is it what you want, from the initial question?*/

run;

ods trace off;

%end;

%MEND DO_BRANCH;

%DO_BRANCH(replicates=2);

/*Why compare your random samples?*/

proc compare base=New_1 compare=New_2 printall;

   title 'Comparing Two Data Sets: Full Report';

run;

View solution in original post

3 REPLIES 3
ballardw
Super User

Are you getting errors or identical output?

If it is identical output it is likely because the seed value in the surveyselect is selecting the same records for each dataset.

Try doing a proc compare on two of the new_ datasets.

A correction would be to increment the seed value using your U macro variable.

desireatem
Pyrite | Level 9

I corrected the proc surveyselect, the data set are different but the code is not working;

data neww;

seed=-1;

  alpha1 = 10;

  beta1 = 10;

  beta2=10;

  do i = 1 to 141;

  Age=40+(5)*rannor(1);

   lambdaT = 0.025; *baseline hazard;

   lambdaC= .03;  *heavy=0.15; *light=0.03;

   er=0+(0.01)*rannor(1);

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

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

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

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

  pibflr= alpha1 + beta1*t + beta2*Age +er;

    output;

  end;

run;

%let pt=pt;

%macro pat(patt=);

%do &pt=1 %to &patt;  /*** I NEED THE BASELINE COVARIATE FOR AGE=0, So for each data below new_1, new_2, I want the first to set the covariates=Pattern_1, covariates=Pattern_2*/

data Pattern_&pt;

age=0;

output;

run;

%end;

%mend pat;

%MACRO DO_BRANCH(replicates=);

%do u=1 %to &replicates;

proc surveyselect data=neww  method = urs sampsize = 141 OUTHITS

     reps=1 samprate=1  seed=-1 out=new_&u;

run;

%pat(patt=2);

ods trace on /listing;

ods graphics on;

ods output ParameterEstimates=CPHH_&u;

proc phreg data=new_&u ;

model monset*obs(0)=age;

*baseline out=survs survival= survival;

baseline covariates=Pattern_&pt out=survs_&u survival= survival;  /* The issue is that SAS doesnot seem to understand that I want covariates=pattern_1 when running the data set new_1 and covariates=pattern_2 for new_2*/

run;

ods trace off;

%end;

%MEND DO_BRANCH;

%DO_BRANCH(replicates=2);

proc compare base=New_1 compare=New_2 printall;

   title 'Comparing Two Data Sets: Full Report';

run;

data Pattern;

Age=0;

output;

run;

ods trace on /listing;

ods graphics on;

ods output ParameterEstimates=CPHH;

proc phreg data=neww;

model monset*obs(0)=age;

baseline covariates=pattern out=survs survival= survival  ;

run;

ods trace off;

Reeza
Super User

Does this do what you expect it do?

Test it %put &pt afterwards to see what it resolves to:

%let pt=pt;

This will create a set of pattern_1, pattern_2 datasets that are identical. Why? There is no point to this, simply have one pattern dataset.

%macro pat(patt=);

%do &pt=1 %to &patt;

data Pattern_&pt;

age=0;

output;

run;

%end;

%mend pat;

%MACRO DO_BRANCH(replicates=);

%do u=1 %to &replicates;

proc surveyselect data=neww  method = urs sampsize = 141 OUTHITS

     reps=1 samprate=1  seed=-1 out=new_&u;

run;

%pat(patt=2); /*this isn't needed, see the above comments regarding why*/

ods trace on /listing;

ods graphics on;

ods output ParameterEstimates=CPHH_&u;

proc phreg data=new_&u ;

model monset*obs(0)=age;

*baseline out=survs survival= survival;

baseline covariates=Pattern_&pt out=survs_&u survival= survival;  /* The issue is that SAS doesnot seem to understand that I want covariates=pattern_1 when running the data set new_1 and covariates=pattern_2 for new_2*/

/*Does macro variable &pt exist here, and is it what you want, from the initial question?*/

run;

ods trace off;

%end;

%MEND DO_BRANCH;

%DO_BRANCH(replicates=2);

/*Why compare your random samples?*/

proc compare base=New_1 compare=New_2 printall;

   title 'Comparing Two Data Sets: Full Report';

run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 952 views
  • 0 likes
  • 3 in conversation