Dear All,
I have a simple question here, I have two list of variables:
%let A= A1 A2 A3;
%let B= B1 B2 B3;
I want to fit a PH regression model with effect of A's and B's and their interaction repectively, i.e. :A1*B1 A2*B2 A3*B3.
I ceded as follow, but this doesn't give me the interaction term i desired, it only gives me A3*B1.
proc phreg data=modeldata;
model followup*pass(0) = &A &B aA*&B ;
run;
Can anyone help address this bug?
Thank youvery much!!
Best wishes,
This is essentially how you could do it, wanted1 is solution 1, and wanted2 is solution 2. Hope this makes sense.
%macro wanted1;
%let A= A1 A2 A3;
%let B= B1 B2 B3;
proc phreg data=_null_;
model followup*pass(0) =
%do i = 1 %to 3;
%let wanta = %scan(&a,&i,' ');
%let wantb = %scan(&b,&i,' ');
&wanta &wantb &wanta*&wantb
%end;
;
run;
%mend;
%wanted1;
%macro wanted2;
%let A= A1 A2 A3;
%let B= B1 B2 B3;
%do i = 1 %to 3;
%let wanta = %scan(&a,&i,' ');
%let wantb = %scan(&b,&i,' ');
proc phreg data=modeldata;
model followup*pass(0) = &wanta &wantb &wanta*&wantb;
run;
%end;
%mend;
%wanted2;
Besides missing an & in A*&B what did you want to create? Since there are many possible variations of possible syntax involving () around individual or groups of variables and the * it helps to know what the desired result for your model statement would be if no macro variables at all were involved.
You can specify interaction terms by including @2 after your variables to get all 2 way interactions.
Model x = a b @2;
No, maybe you need the bar between them. What does the documentation say? I'd have to reference it to verify anyways.
Can you add bars between variables in your macrovarisble?
Before you attempt a macro solution you should have a working base case without macro variables.
Show the entire code of the procedure that was working before the introduction of macro variables.
Which are you trying to get as an a running model?
Example 1)
proc phreg data=modeldata;
model followup*pass(0) = A1 A2 A3 B1 B2 B3 A1*B1 A2*B2 A3*B3 ;
run;
OR
Example 2)
proc phreg data=modeldata;
model followup*pass(0) = A1 B1 A1*B1;
run;
proc phreg data=modeldata;
model followup*pass(0) = A2 B2 A2*B2;
run;
proc phreg data=modeldata;
model followup*pass(0) = A3 B3 A3*B3;
run;
Because the way to do them is very different.
This is essentially how you could do it, wanted1 is solution 1, and wanted2 is solution 2. Hope this makes sense.
%macro wanted1;
%let A= A1 A2 A3;
%let B= B1 B2 B3;
proc phreg data=_null_;
model followup*pass(0) =
%do i = 1 %to 3;
%let wanta = %scan(&a,&i,' ');
%let wantb = %scan(&b,&i,' ');
&wanta &wantb &wanta*&wantb
%end;
;
run;
%mend;
%wanted1;
%macro wanted2;
%let A= A1 A2 A3;
%let B= B1 B2 B3;
%do i = 1 %to 3;
%let wanta = %scan(&a,&i,' ');
%let wantb = %scan(&b,&i,' ');
proc phreg data=modeldata;
model followup*pass(0) = &wanta &wantb &wanta*&wantb;
run;
%end;
%mend;
%wanted2;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.