Jerry,
You didn't provide any sample data, or expected results, thus one can only guess. I'm sure some regex experts can come up with something better, but the following appears to come close to what you want:
[pre]
data inq;
informat subject $60.;
input subject &;
cards;
Fake subject no context
Another fake subject Inquiry#1 but not sure
Yet another fake subject Inquiry#12
Yet another fake subject Inquiry#13 but this is more
This line doesn't have Inquiry# followed by any digit(s)
;
data inq_2 ;
set inq ;
inq_pos = index(subject , 'Inquiry#') ;
if inq_pos gt 0 then do;
str1=substr(subject,1,inq_pos-1);
if anydigit(substr(subject,inq_pos+8,1)) then
str2=substr(subject,inq_pos+9);
else str1="";
if anydigit(substr(subject,inq_pos+9,1)) then
str2=substr(subject,inq_pos+10);
end;
run ;
[/pre]
HTH,
Art
---------
> I have a data set that has a subject variable. This
> is based on email subjects.
> The issue I'm having is that I have to find a
> specific string within this variable but the string
> isn't consistent. The string 'Inquiry#' is what i'm
> looking for but it has to have 1 or 2 numbers
> following it. For ex Inquiry#1 or Inquiry#12.
>
> I need the string before and after this string. I
> have done this so far but I feel I could have done it
> much cleaner.
>
>
> data inq_2 ;
> set inq ;
>
> subject_ = compress(subject) ;
> inq_pos = find(subject_ , 'Inquiry#', 'i') ;
> inq_str = substr(subject_ , inq_pos) ;
> inq_dash_pos = find(inq_str, '-') ; /*A dash does
> s not always follow. Needs fix */
>
> if inq_pos = 1 then x = substr(subject_ ,
> , inq_dash_pos) ;
> else x = substr(subject_,1,inq_pos -1) || ' ' ||
> | substr(subject_, (inq_pos + inq_dash_pos) - 1) ;
>
> run ;
>
> Thanks for any help