DATA Step, Macro, Functions and more

print all combinations of upper and lowercase of string

Reply
Frequent Contributor
Posts: 85

print all combinations of upper and lowercase of string

Is it possible to get all combinations of two word string in SAS and print it in log

E.g. My string is always

Codes find

And I want output like

Codes Find

cOdes fInd

CoDeS fiNd

.

.

.

Like this. My string contains 2 words. First word of 5 letters then a blank space and then 4 letter word.

I know that we can use regex for this . But somehow I am unable to get it solved.

Many thanks in advance

Super User
Posts: 9,691

Re: print all combinations of upper and lowercase of string

Not really. PRX is hard for this, But easy for data step:

data have;
string='Codes find';
run;
data _null_;
 set have;
 call symputx('n',length(string));
run;
data want;
set have;
array x{&n};
n=dim(x);
k=-1;
nsubs=2**n;
do i=1 to nsubs;
string=lowcase(string);
rc=graycode(k, of x{*});
 do j=1 to dim(x);
  if x{j}=1 then substr(string,j,1)=upcase(substr(string,j,1));
 end;
 output;
end;
keep string;
run;


Xia Keshan

Ask a Question
Discussion stats
  • 1 reply
  • 262 views
  • 0 likes
  • 2 in conversation