From: bcubeb3 on
The first data statement runs find. I am trying to replicate the right
function found in Excel in SAS. However I wrote the macro for it but I
am not sure if the way I am doing it is right.
It is not giving me the result I want.

/** mini program starts here */
data _null_;
x='1-(310)-720-4206';
y = compress(x,'-()');
put y;
run;

%macro right(vn,len);
reverse(substr(reverse(&vn),1,&len))
%mend;
%macro reverse(string);
%local i rstring;
%let rstring=;
%let string=&quote(&string);
%do i=%lenght(&string) %to 1 %by -1; %quote(%substr(&string,&i,1))
%end;
%mend;

%right(y,7);
From: data _null_; on
On Jun 17, 10:35 am, bcubeb3 <barry.brian.barr...(a)gmail.com> wrote:
> The first data statement runs find. I am trying to replicate the right
> function found in Excel in SAS. However I wrote the macro for it but I
> am not sure if the way I am doing it is right.
> It is not giving me the result I want.
>
> /** mini program starts here */
> data _null_;
> x='1-(310)-720-4206';
> y = compress(x,'-()');
> put y;
> run;
>
> %macro right(vn,len);
> reverse(substr(reverse(&vn),1,&len))
> %mend;
> %macro reverse(string);
> %local i rstring;
> %let rstring=;
> %let string=&quote(&string);
> %do i=%lenght(&string) %to 1 %by -1; %quote(%substr(&string,&i,1))
> %end;
> %mend;
>
> %right(y,7);

148 data _null_;
149 x='1-(310)-720-4206';
150 y = compress(x,'-()');
151 put y;
152
153 right7 = substrN(y,lengthN(y)-6);
154 put right7;
155
156 run;

13107204206
7204206
From: bcubeb3 on
You see that really isn't the way I want to do it due to the following
reasons.

there could be instances where the number could be like this:
13107204206
and others like
3107204206
so I really just want the last 7 digits from the right,
since the form of the number could have an extra 1 in the front and
other times like this
013107204206
Let me know of a better more accurate solution.

-Barry
On Jun 17, 11:40 am, "data _null_;" <datan...(a)gmail.com> wrote:
> On Jun 17, 10:35 am, bcubeb3 <barry.brian.barr...(a)gmail.com> wrote:
>
>
>
>
>
> > The first data statement runs find. I am trying to replicate the right
> > function found in Excel in SAS. However I wrote the macro for it but I
> > am not sure if the way I am doing it is right.
> > It is not giving me the result I want.
>
> > /** mini program starts here */
> > data _null_;
> > x='1-(310)-720-4206';
> > y = compress(x,'-()');
> > put y;
> > run;
>
> > %macro right(vn,len);
> > reverse(substr(reverse(&vn),1,&len))
> > %mend;
> > %macro reverse(string);
> > %local i rstring;
> > %let rstring=;
> > %let string=&quote(&string);
> > %do i=%lenght(&string) %to 1 %by -1; %quote(%substr(&string,&i,1))
> > %end;
> > %mend;
>
> > %right(y,7);
>
> 148  data _null_;
> 149     x='1-(310)-720-4206';
> 150     y = compress(x,'-()');
> 151     put y;
> 152
> 153     right7 = substrN(y,lengthN(y)-6);
> 154     put right7;
> 155
> 156  run;
>
> 13107204206
> 7204206

From: data _null_; on
On Jun 17, 1:05 pm, bcubeb3 <barry.brian.barr...(a)gmail.com> wrote:
> You see that really isn't the way I want to do it due to the following
> reasons.
>
> there could be instances where the number could be like this:
> 13107204206
> and others like
> 3107204206
> so I really just want the last 7 digits from the right,
> since the form of the number could have an extra 1 in the front and
> other times like this
> 013107204206
> Let me know of a better more accurate solution.
>
> -Barry
> On Jun 17, 11:40 am, "data _null_;" <datan...(a)gmail.com> wrote:
>
>
>
> > On Jun 17, 10:35 am, bcubeb3 <barry.brian.barr...(a)gmail.com> wrote:
>
> > > The first data statement runs find. I am trying to replicate the right
> > > function found in Excel in SAS. However I wrote the macro for it but I
> > > am not sure if the way I am doing it is right.
> > > It is not giving me the result I want.
>
> > > /** mini program starts here */
> > > data _null_;
> > > x='1-(310)-720-4206';
> > > y = compress(x,'-()');
> > > put y;
> > > run;
>
> > > %macro right(vn,len);
> > > reverse(substr(reverse(&vn),1,&len))
> > > %mend;
> > > %macro reverse(string);
> > > %local i rstring;
> > > %let rstring=;
> > > %let string=&quote(&string);
> > > %do i=%lenght(&string) %to 1 %by -1; %quote(%substr(&string,&i,1))
> > > %end;
> > > %mend;
>
> > > %right(y,7);
>
> > 148  data _null_;
> > 149     x='1-(310)-720-4206';
> > 150     y = compress(x,'-()');
> > 151     put y;
> > 152
> > 153     right7 = substrN(y,lengthN(y)-6);
> > 154     put right7;
> > 155
> > 156  run;
>
> > 13107204206
> > 7204206- Hide quoted text -
>
> - Show quoted text -

You see, I think you need to test the code. I believe it works as you
say you want. Show an exampe where it does not work properly.
 | 
Pages: 1
Prev: Ab Initio Developers
Next: how to lock a column