Hi,
Given a set of values, say A B and C, I need to generate the following from it:
A
B
C
A B
A C
B C
A B C
I've looked at the permutation functions that those don't seem to fit. Not sure about Proc Plan either. Data step would be prefereable but not required.
Thanks!
--Ben
is the output supposed to be a data set or text output? Do you want a single variable with the "value" or something such as a series of variables that is populated with the desired pieces?
It may help to indicate how you are getting the values that you need to combine. Do you have list or a data set? And how many actual values are you going to be concerned with?
This comes pretty close:
data junk; array x[3] $3 ('a' 'b' 'c' ); array h[3] $3 ; n=dim(x); do k=1 to 3; ncomb=comb(n, k); call sortc(of x(*)); /* empty target array*/ call missing (of h(*)); do j=1 to ncomb; rc=allcomb(j, k, of x[*]); if rc<0 then leave; do i=1 to k; h[i]=x[i]; end; longstr= cats(of h(*)); output; end; end; drop i j k n ncomb rc; run;
if the want is a single variable look at the longstr, if array look at h. You may want to sort the data set if order is critical.
is the output supposed to be a data set or text output? Do you want a single variable with the "value" or something such as a series of variables that is populated with the desired pieces?
It may help to indicate how you are getting the values that you need to combine. Do you have list or a data set? And how many actual values are you going to be concerned with?
This comes pretty close:
data junk; array x[3] $3 ('a' 'b' 'c' ); array h[3] $3 ; n=dim(x); do k=1 to 3; ncomb=comb(n, k); call sortc(of x(*)); /* empty target array*/ call missing (of h(*)); do j=1 to ncomb; rc=allcomb(j, k, of x[*]); if rc<0 then leave; do i=1 to k; h[i]=x[i]; end; longstr= cats(of h(*)); output; end; end; drop i j k n ncomb rc; run;
if the want is a single variable look at the longstr, if array look at h. You may want to sort the data set if order is critical.
Actually that's perfect! I was going to chuck the values into an array statement for the real problem and this is what I was looking for.
Thank you so much!
--Ben
data _null_;
array c[3] $ ('a' 'b' 'c');
array x[3];
length comb $ 400;
n=dim(x);
k=-1;
nsubs=2**n;
do i=1 to nsubs;
rc=graycode(k, of x[*]);
call missing(comb);
do j=1 to n;
if x[j]=1 then comb=catx(' ',comb,c[j]);
end;
if not missing(comb) then putlog comb= ;
end;
run;
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.
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.