Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Combination macro for Regression with a twist

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 10-30-2014 09:33 AM
(2666 views)

Hi All,

I have seen references for combination macros where you can consistently select any 2 combination output with 4 options possible. But if I want to automatically select every 1 to n (in this case n=4) combination.

data auto;

input y x1 x2 x3 x4;

datalines;

a 1 2 3 5

f 2 3 2 4

;

run;

What if I want to select variables x1-x4 such that following combinations are generated:

1. x1

2. x1 x2

3. x1 x2 x3

4. x1 x2 x3 x4

5. x4 x3 x2

6. x3 x2

.....and so on

Have you guys come across this problem? I want to use it in proc model to generate output for any possible combination of indpendent variables.

Cheers

Jane

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi,

You can use start and stop options to get all possible combination of indpendent variables.

proc reg data=have;

model y=x1 x2 x3 x4/selection=rsquare start=1 stop=4 stb adjrsq cp mse sse;

run;

quit;

9 REPLIES 9

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Are you trying to build model statements for proc reg or select variables in a dataset?

Is the ORDER of the result going to matter at all?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi,

I am trying to select variables for the model.

The order isn't important.

If I were to write the model statement manually then it would be something like below for dataset auto:

1. model y = x1 x2 x3 x4;

2. model y = x1 x4;

3. model y= x2 x3 x4;

....etc.

Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

If you just want those combinations then a do loop can generate it (you could then use that to generate you model lines):

data want;

length mod $200;

retain mod;

do i=1 to 4;

do j=i to i+3;

test=j;

if test > 4 then test=test-4;

mod=catx(' ',strip(mod),'x'||put(test,1.));

output;

end;

mod='';

end;

run;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I think that this might be a better fit:

This datastep generates macro variables as well as a data set you can examine before going to the next part.

data work.junk;

array x[4] $10 _temporary_ ('Var1' 'Var2' 'Var3' 'Var4'); /* replace 10 with length of the longest variable name*/

length longstring $ 200; /* replace 200 with a value long enough to hold all of the variables + one space for each variable*/

length name $ 15;

_n_=dim(x);

do _k_ = 1 to 4;

ncomb= comb(_n_,_k_);

do _j_ = 1 to ncomb;

longstring = '';

call allcomb(_j_,_k_, of x

do _z_= 1 to _k_;

longstring = catx(' ',longstring,x[_z_]);

end;

counter + 1;

c= put(counter,best8.);

Name = cats('Comb',c);

output;

end;

end;

call symputx('CombCount',C);

run;

And use that in a Macro

%macro myreg;

proc reg <options>;

<other statements>

%do I = 1 to &CombCount;

model y = &&comb&i ;

%end;

run;

%mend;

%myreg;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi,

Thanks for the reply.

Unfortunately can't use the code as 'allcomb' seems to be a sub routinue introduced in 9.2 for what i understand. I have 9.1.

Regards,

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi,

You can use start and stop options to get all possible combination of indpendent variables.

proc reg data=have;

model y=x1 x2 x3 x4/selection=rsquare start=1 stop=4 stb adjrsq cp mse sse;

run;

quit;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi

Very interesting use of start and stop. Didn't knew these options existed.

Given the output I am assuming the model selection methodology is based on C(p), MSE and SSE.

Is there a way to populate the paramater estimates for the model combinations that haven't been selected as final models. It would be interesting to see how the coefficients change with respect to other non-significant variables.

Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

you can use proc summary to get all of combination of them.

data auto; input y x1 x2 x3 x4; datalines; 3 1 2 3 5 3 2 3 2 4 ; run; data temp; set sashelp.vcolumn(where=(libname='WORK' and memname='AUTO' and name like 'x%')); keep name; run; proc transpose data=temp out=x(drop=_:);var name;run; proc summary data=x ; class col:; output out=y; run; data want; set y; combine=catx(' ',of col:); keep combine; run;

Xia Keshan

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

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.