turn on suggestions

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

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Pick variables in different combinations

Topic Options

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-24-2015 05:15 PM

Is there any way we can use variables in different combinations in a macro? For example, there are 3 variables - Var 1 Var2 Var3.

Possible combinations i would like to make ---

Var1

Var2

Var3

Var1 Var2

Var1 Var3

Var2 Var3

Var1 Var2 Var3

Order does not matter (Var1 Var2 Var3 and Var2 Var1 Var3 - Same).

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ujjawal

06-24-2015 05:18 PM

What do you mean by use variables in different combination?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

06-25-2015 03:58 PM

What i really want to accomplish - Look at the macro below . In this case, it is selecting variables one by one and testing it as an independent variable in single linear regression model. I want the different combinations of variables to be used and testing it as independent variables in regression model.

%macro regcomb ( input =, depvar =, vars=);

%let n=%sysfunc(countw(&vars));

%do i=1 %to &n;

%let val = %scan(&vars,&i);

ods select none;

ods output ParameterEstimates=Estimate&i;

proc reg data = input;

model &depvar. = &val.;

run;

data &output;

set Estimate1 - Estimate&n;

run;

%mend;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ujjawal

06-25-2015 04:24 PM

Look at the results of this and the VARLIST macro variable.

%macro test;

%let v1= Var1;

%let v2= Var2;

%let v3= Var3;

%let v4= Var4;

%let v5= Var5;

%do k=1 %to 3;

%let ncomb=%sysfunc(comb(5,&k));

%do j=1 %to &ncomb;

%syscall allcomb(j, k, V1, V2, V3, V4, V5);

%let varlist=;

%do i = 1 %to &k; %let varlist=&varlist &&V&i; %end ;

%put &varlist;

%end;/*j loop*/

%end;/*k loop*/

%mend;

%test

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ballardw

06-25-2015 04:59 PM

Thanks Ballardw. I will try and let you know about it. You are always a great help. I bow down to you :-)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ujjawal

06-24-2015 05:22 PM

I would start by looking in the online documentation for the Call Allcomb function which has an example of use within a macro.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ujjawal

06-24-2015 05:58 PM

PROC PLAN does this kind of thing also.

Tom

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ujjawal

06-25-2015 04:55 AM

This might not be what you are after but this sort of does what you ask for.

data Vars;

input Variables $ ;

cards;

Var1

Var2

Var3

;

proc sql;

select *

from Vars as a, vars as b, vars as c

;

quit;

The proc sql does a self join and you get all combinations. Maybe you can work towards your goal from this.