Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is this even possible in SAS? 1

Status
Not open for further replies.

cosmid

Programmer
Feb 14, 2008
73
US
I have 50 variables named narrative1-narrative50. It all describes one field, narrative.

Objective: Creat an indicator variable to the data set to index for the following words: assault, injury..etc.

hm...these fields in the narrative1-narrative50 are really long...they are all sentences describing something. How do I search through them and pick out the words that I wanted?
 
Ahh...how do you edit a post? I need to change the objective. Let me state the above post again here.

I have a data set that has 50 fields, narrative1-narrative50.

Objective: Creat an indicator variable. Find the words, assult, injury..etc. in these narrative fields, if any of the words listed existed, mark the indicator for that record.

So, pretty much the indicator is like a boolean variable. My problem is, how do you search through a string field to look for a particular word? And now I got 50 fields.
 
Have you tried using the indexw() function? This returns the first occurence of the search string.

here is an example

Code:
data test;
  set yourdata;
  array allvars (*) narrative1-narrative50;

  do i=1 to 50;
    if indexw(upcase(allvars(i)),'ASSUALT') gt 0  then
      newindix = 1;
  end;
run;

I hope this helps you get the picture. There are also some PERL-type string functions in SAS version 9 that could help you.
Klaz
 
Thanks! PERL can be used in SAS just like SQL can be used in SAS?
 
cosmid - kind of, there's a bunch of PRX... functions you can use for pattern matching which are based on PERL Regular Expressions.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
hm..that's an area where I need to explore. I heard PERL is very useful. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top