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

I have generated dummy variables for every year as below

Data work;
     set work;

     array yrdummy(*) d_&startyr - d_&endyr;
     do i=1 to dim(yrdummy);
     if fyear = i+&startyr then yrdummy{i} = 1;
     else yrdummy{i} = 0;
     end;
     drop i;
run;

Now I want to interact every d_'year' with a variable. For example, I have a dummy called 'd_group'. I want to interact d_group with d_1988 through d_2018 so that I am left with variables called d_group*d_1988 through d_group*d_2018. Is there a loop to make this happen?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Modeling procedures in SAS (such as PROC GLM and many others) create the interactions for you. So all you have to do is specify the desired model (with main effects and interactions) and you don't have to create dummy variables.

 

This code fits a model with all two-way interactions of X1 X2 X3 X4 X5, no dummy variables needed

 

proc glm data=have;
    class x1-x5;
    model y=x1|x2|x3|x4|x5@2;
run;
quit;
--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Yes there can be a loop to do this, but why do you need these dummy variables? Many SAS procedures create dummy variables internally, so you don't have to create them yourself.

--
Paige Miller
kelSAS
Obsidian | Level 7

I want to compare two coefficients of the same model with two different sample. To do so, I need to interact all variables in the model with the dummy variable that divides total observations into the two different samples. 

 

I want to display tables that have the coefficients on all variables with one sample and the same with the other sample, and the third column would show the difference between the two samples. Because the fixed effects are going to change the coefficients if I run the two samples separately, I need to have all variables interacted with the indicator variable and include in the model. 

 

Can you tell me how to create the loop, please?

PaigeMiller
Diamond | Level 26

Modeling procedures in SAS (such as PROC GLM and many others) create the interactions for you. So all you have to do is specify the desired model (with main effects and interactions) and you don't have to create dummy variables.

 

This code fits a model with all two-way interactions of X1 X2 X3 X4 X5, no dummy variables needed

 

proc glm data=have;
    class x1-x5;
    model y=x1|x2|x3|x4|x5@2;
run;
quit;
--
Paige Miller
StatDave
SAS Super FREQ

You might be trying to do what is described in this note

kelSAS
Obsidian | Level 7
Thanks, but this only handles one group. I have about 300 groups.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 2738 views
  • 2 likes
  • 3 in conversation