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

Hi All,
Here is the original dataset:

data m01;

a="CGA  AMZN.COM   CA";output;

a="CHA  AMZN.COM   HK";output;

run;

Output dataset like:
Word

CGA
AMZN.COM
CA
CHA
AMZN.COM
HK


Any idea?

Here is mine:

data m02;

set m01;

an=translate(a,"@"," ");

run;

data m02_1;

set m02;

an=tranwrd(an,"@@","@");

run;

%macro REEE;

%do i=1 %to 10;

data m02_1;

set m02_1;

an=tranwrd(an,"@@","@");

run;

%end;

%mend;

%REEE;

data m03;

set m02_1;

bn=an;

No=_N_;

j=0;

do until(j=0);

j=find(bn,"@");

i=1;

Word=substr(bn,i,j-i);

i+j;

bn=substr(bn,i,j-i);

output;

end;

run;

In fact the original dataset contains thousands of merchants description,I want to break it down into words.
What's your suggestion,please?

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
CTorres
Quartz | Level 8

You can do this in only one step using functions COUNTW and SCAN specifing the blank as separator of words.

data want ;

length word $ 20;

set m01;

do i = 1 to countw(a,' ');

   word=(scan(a,i,' '));

   output;

end;

run;

Regards,

View solution in original post

2 REPLIES 2
Peter_C
Rhodochrosite | Level 12

more _infile_ magic at http://www2.sas.com/proceedings/sugi28/086-28.pdf

shows a way to use the parsing of the input statement on data that comes from a table or data set variable.

Then you can populate a hash table of word counters, in a single pass.

CTorres
Quartz | Level 8

You can do this in only one step using functions COUNTW and SCAN specifing the blank as separator of words.

data want ;

length word $ 20;

set m01;

do i = 1 to countw(a,' ');

   word=(scan(a,i,' '));

   output;

end;

run;

Regards,

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 845 views
  • 3 likes
  • 3 in conversation