Desktop productivity for business analysts and programmers

Working with Delimit in SAS EG

Reply
Contributor
Posts: 24

Working with Delimit in SAS EG

Hey all,

I would like to seek some help and solutions through this discussion thread.
Currently, i am working on a column with the content for teacher's comment.

Then i would like to delimit it by the space or comma or punctuation marks between words inside the content.

At the same time , i would like to take out each of the words in the content and then place them into rows instead of columns .

Example .
Catherine is a good girl . -> This is the teacher's comment.

After delimit and placing them into rows in SAS dataset , it would look like this in 5 rows :
Catherine
is

a

good

girl

Thank you all .

Regards,
Cody

Contributor QLi
Contributor
Posts: 59

Re: Working with Delimit in SAS EG

If you use Enterprise Guide, you can follow these steps.

From" File" in the tool Bar , select "Import Data", 

Click "Text Format "  , select "Delimited" in the format and select "Space" in the  Delimiter

Click Run.

Try it and good luck

Trusted Advisor
Posts: 2,114

Re: Working with Delimit in SAS EG

Cody,

QLi's approach should put each word into its own variable (you may need to add the MISSOVER option to allow for different number of words in each comment).  You can then use the transpose task (tasks --> data --> transpose) to get the words into rows.

Doc Muhlbaier

Duke

Contributor
Posts: 24

Re: Working with Delimit in SAS EG

Hi Doc Muhlbaier and QLi,

After putting each word into its own variable, how do I put the few rows into one column instead?

a     b     c

d     e     f

g     h     i

to

a

b

c

d

e

f

g

h

i

Thanks

Super Contributor
Posts: 349

Re: Working with Delimit in SAS EG

Hi,

Try this..

data one;

input comments $ :15. @@;

cards;

Catherine is a good girl

;

run;

data two;

input one $ two $ three $;

cards;

a     b     c

d     e     f

g     h     i

;

run;

data want;

set two;

array xx[3] one two three;

do i=1 to dim(xx);

if xx ne '' then yy=xx;

output;

end;

drop one--three i;

run;

Thanks,

Shiva

Contributor
Posts: 24

Re: Working with Delimit in SAS EG

Hi Shivas,


Thanks for your reply. I have tried it and it worked.
However, my concern is that the data which I am using is of a large scale (2000 of values)
Do you have any way which I could work around it ?
Is there a way to import the file which it will automatically change to the 1 column , many rows output.

Thank you.

Regards,
Cody

Contributor
Posts: 24

Re: Working with Delimit in SAS EG

Hi Shivas,


Thanks for your reply. I have tried it and it worked.
However, my concern is that the data which I am using is of a large scale (2000 of values)
Do you have any way which I could work around it ?
Is there a way to import the file which it will automatically change to the 1 column , many rows output.

Thank you.

Regards,
Cody

Occasional Contributor
Posts: 8

Re: Working with Delimit in SAS EG

How about something like this:

filename in_file 'your_text_file' lrecl=32767;

/* split words separated by spaces */
data in_file;
infile in_file length=l;
length word_nospace $50.;
keep word_nospace;
  input record $varying32767. l;
  delims=count(trim(record), ' ')+1;
  do i=1 to delims;
   word_nospace=scan(record, i, ' ');
   output;
  end;
run;

/* split words separated by commas */
data in_file;
set in_file;
keep word_nocomma;
  delims=count(word_nospace, ',')+1;
  do i=1 to delims;
   word_nocomma=scan(word_nospace, i, ',');
   if not missing(word_nocomma) then output;
  end;
run;

Ask a Question
Discussion stats
  • 7 replies
  • 316 views
  • 9 likes
  • 5 in conversation