BookmarkSubscribeRSS Feed
forumsguy
Fluorite | Level 6

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

1 REPLY 1
Ksharp
Super User

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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1415 views
  • 0 likes
  • 2 in conversation