Desktop productivity for business analysts and programmers

Index

Reply
N/A
Posts: 0

Index

%let a=ex_table_case_23jan2008;


i have to extract "23jan2008" string.
here _ is a delimeter .i have to extract the string which come after last occurance of _ (underscore) in macro variable a.

please help...
N/A
Posts: 0

Re: Index

%let last_bit = %scan( &A, -1, _ );

PeterC
N/A
Posts: 0

Re: Index

sorry ..

i have to extract "ex_table_case" from the macro variable a.
N/A
Posts: 0

Re: Index

sorry that was not obvious from your request.
Try this[pre] %let a=ex_table_case_23jan2008;
%let last_bit = %scan( &A, -1, _ );

%let rev1_ = %sysfunc(reverse( &a )) ;
%let last_ = %sysfunc(index( &rev1_, _ )) ;
%let rest_ = %substr(&rev1_,%eval(1+&last_)) ;
%let wanted = %sysfunc( reverse(&rest_));

%put wanted = &wanted ;[/pre]That gives me:[pre]71 %let a=ex_table_case_23jan2008;
72
73 %let last_bit = %scan( &A, -1, _ );
74 %let rev1_ = %sysfunc(reverse( &a )) ;
75 %let last_ = %sysfunc(index( &rev1_, _ )) ;
76 %let rest_ = %substr(&rev1_,%eval(1+&last_)) ;
77 %let wanted = %sysfunc( reverse(&rest_));
78
79 %put wanted = &wanted ;
wanted = ex_table_case[/pre]

PeterC
N/A
Posts: 0

Re: Index

Thanks Peter_c

i want to ask one more thing..using index(), it is not possible to find last occurance of _ (underscore ) in the string &a.
N/A
Posts: 0

Re: Index

I would have, if I could have..... , unless, perhaps you can achieve it with regular expression handling...... over to you ...


PeterC
SAS Employee
Posts: 149

Re: Index

Hi Arvind,

INDEX can only search forward -- PeterC's technique of using INDEX and REVERSE definitely works in this way. There is a new SAS 9 function, FIND, which is like INDEX but with more bells and whistles. In particular, it can search backwards.

http://support.sas.com/documentation/cdl/en/lrdict/59540/HTML/default/a002267763.htm

data _null_;
call symputx("lastu",find("&a","_",-9999));
run;
/* The -9999 is just an arbitrary number longer than
the text string. This forces a backward search. */

%let soln2=%substr(&a,1,%eval(&lastu-1));

Changed original reply - I wasn't looking carefully enough at the revised request for ex_table_case ... this should now work!


Message was edited by: RichardH Message was edited by: RichardH
N/A
Posts: 0

Enterprise Guide

Hi I am writing a program and I was wondering if I should use Enterprise Guide or SAS programming. I need to use substrings, can I use substrings using enterprise guide. Lets say for example I have a Date of Visit and I need only certain years and certain months within those years. Can I do this using Enterprise Guide.

Thanks for your help.

Rabiya
N/A
Posts: 0

Re: Enterprise Guide

for a new qustion, please start a new thread
Ask a Question
Discussion stats
  • 8 replies
  • 195 views
  • 0 likes
  • 2 in conversation