BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rahul_SAS
Quartz | Level 8

Hi Experts,

 

I am trying to get all combinations of words in preceding order available in a given string e.g.

 

Suppose I have a string  like "The cow jumps over the moon"

and want combinations like..

The cow

The jumps

The over

The the

The Moon

cow jumps

cow over

cow the

cow moon

jumps over

jumps the

jumps moon

over the

over moon

the moon

 

please help me to achieve the same..

I m trying the following code:

 

data test;
sen = "The cow jumps over the moon";
run;


data test1;
set test;
length sen1 $100.;
sen1="";
retain sen1;
do i=0 to count(compbl(TRIM(sen))," ");
do j=1 to 2;
sen1=compbl(sen1||" "||compbl(trim(scan(compbl(TRIM(sen)),i+j," ","MO"))));
ngram= j;
r=count(TRIM(sen)," ");
x=count(compbl(TRIM(sen))," ");
output;
end;
sen1="";
end;
if ngram=2;
run;

 

Thnx

Rahul

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Using the data you already have:

 

data want;

set test;

nitems = countw(sen);

length combo $ 100;

if nitems > 1;

do i=1 to nitems - 1;

do j=i+1 to nitems;

   combo = catx(' ', scan(sen, i), scan(sen, j));

   output;

end;

run;

View solution in original post

5 REPLIES 5
user24feb
Barite | Level 11
Data A;
  Input Text : $ Nr @@;
  Datalines;
The 1 cow 2 jumps 3 over 4 the 5 moon 6
;

***2nd select did not really make sense ..*; Proc SQL; Create Table B As Select a1.Text As Text1,a2.Text As Text2 From A a1,A a2 Where a1.Nr lt a2.Nr ; Quit;
Astounding
PROC Star

Using the data you already have:

 

data want;

set test;

nitems = countw(sen);

length combo $ 100;

if nitems > 1;

do i=1 to nitems - 1;

do j=i+1 to nitems;

   combo = catx(' ', scan(sen, i), scan(sen, j));

   output;

end;

run;

maxweyrick
Calcite | Level 5

Hey dude I need your number. Your coding concept with SAS is really close to something that is pretty cool and I am willing to give you a % of the money my fully developed code is worth.

 

Max

 

4045380741

Astounding
PROC Star

These message boards make it easy to send private messages.  But you have to enable that feature for your userid.

 

Assuming you were talking to me, I know that I can't take on any new projects until the end of the summer.

maxweyrick
Calcite | Level 5

Yo dude if you make all possible combos with characters and numbers it would be worth even more as a software.

 

Max

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 2317 views
  • 1 like
  • 4 in conversation