From: abose on
Hi,
Suppose I want to check if a macro variable ends with some particular
string. How can I do that?

For example,
%let var1=FRIENDSNAME;
%let var2=FRIENDSAGE;

Then &var1 ends with NAME, &var2 ends with AGE.
From: Patrick on
In general: You could use %substr() or %scan()

But how do you know where "the end" begins? In your example: What
tells you that the end is not SNAME and SAGE?
From: data _null_; on
On May 6, 2:18 am, abose <hira...(a)gmail.com> wrote:
> Hi,
> Suppose I want to check if a macro variable ends with some particular
> string. How can I do that?
>
> For example,
> %let var1=FRIENDSNAME;
> %let var2=FRIENDSAGE;
>
> Then &var1 ends with NAME, &var2 ends with AGE.

Perhaps the COMPARE function would be helpful.

887 %let var1=FRIENDSNAME;
888 %let var2=FRIENDSAGE;
889
890 %let dif = %sysfunc(compare(&var1,&var2));
891 %put NOTE: dif=&dif;
NOTE: dif=8
From: Tom Abernathy on
Not sure what you mean but if want to test if a variable ends in a
string then reverse the strings and use index function to test if
first version found starts in column 1.

56 %let var1=FRIENDSAGE;
57 %let var2=NAME;
58 %let endswith=%eval(1=%index(%sysfunc(reverse(&var1)),
%sysfunc(reverse(&var2))));
59
60 %put var1=&var1 var2=&var2 endswith=&endswith;
var1=FRIENDSAGE var2=NAME endswith=0

61 %let var1=FRIENDSAGE;
62 %let var2=AGE;
63 %let endswith=%eval(1=%index(%sysfunc(reverse(&var1)),
%sysfunc(reverse(&var2))));
64
65 %put var1=&var1 var2=&var2 endswith=&endswith;
var1=FRIENDSAGE var2=AGE endswith=1


On May 6, 3:18 am, abose <hira...(a)gmail.com> wrote:
> Hi,
> Suppose I want to check if a macro variable ends with some particular
> string. How can I do that?
>
> For example,
> %let var1=FRIENDSNAME;
> %let var2=FRIENDSAGE;
>
> Then &var1 ends with NAME, &var2 ends with AGE.