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
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;
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;
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;
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
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.
Yo dude if you make all possible combos with characters and numbers it would be worth even more as a software.
Max
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.