BookmarkSubscribeRSS Feed
zhuxiaoyan1
Quartz | Level 8

I need to do a linear regression. I have about 30 independent variables in a sas data set. Is there a way to put those variables in the model statement without typing them?

LN_ADJ_Cost ADH CFA Pneu Diabetes ........and much more columns

465             1       1      1          0

543              0       1      1          1

.

.

.

.

  proc reg data=cost;

  model  LN_ADJ_Cost= ADH CFA Pneu Diabetes .......... / selection=backward sls=0.5 collin VIF;

run; quit;

 

 

2 REPLIES 2
ballardw
Super User

I am assuming your variables weren't named ahead of time to use the Var1 - Var30 list notation.

If your variables have common name stems, the first letters are in common the you could use the : variable list notation  ADH: would include all variables whose names start with ADH.

 

If the variables are next to each other in the data set such as column 5 through (something larger than 5) you can use the double dash to indicate them   Var1 -- adh57 would get all the variables adjacent with var1 and adh57 included. If you have multiple blocks you could use more than one set of these:   Var1 -- adh57   pdq -- xyz would the variables from pdq to xyz that are adjacent to the list from the first bit.

If some of your variables are named Varxx to Varyy with x and y numers you can use Varxx-Varyy mixed with the other lists bits.

 

zhuxiaoyan1
Quartz | Level 8

this is nice But I got another approach. Since my independent vars change as data change. I create a macro var and store the independent vars in a macro var, then I don't have to worry about this even my data change.

proc contents daa=For_Reg out=stuff;

run;

proc sql noprint;

  select distinct name

  into Var separated by ' '

  from stuff whewe type=2 and name not EQ 'LN_ADJ-Cost';

quit;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 1502 views
  • 2 likes
  • 2 in conversation