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
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
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
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
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
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
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
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.