Solved
SAS Employee
Posts: 8

# =RIGHT(X,10) EXCEL STYLE FUNCTION ON SAS

Hi,

How can the below excel function coded in SAS?

 VAR01 VAR02 1234567890123 =RIGHT(A2,10)

The result must be "4567890123".

Thanks,

Olp

Accepted Solutions
Solution
‎10-25-2014 08:56 AM
Super User
Posts: 10,787

## Re: =RIGHT(X,10) EXCEL STYLE FUNCTION ON SAS

No. if it is character. I would write this.

data test;

v1='1234567890123';

v2=substr(strip(v1),length(v1)-9);

put v1= v2= ;

run;

Xia Keshan

All Replies
Posts: 3,215

## Re: =RIGHT(X,10) EXCEL STYLE FUNCTION ON SAS

There is no straightforward equal name function. SAS(R) 9.4 Functions and CALL Routines: Reference, Third Edition  substr can do the job when you give the position. (length - ... )

There are a lot of functions in SAS it could be your soltion is easier thinking in SAS than in Excel.

---->-- ja karman --<-----
Super User
Posts: 10,787

## Re: =RIGHT(X,10) EXCEL STYLE FUNCTION ON SAS

It was character type or numeric type ?

```data _null_;
v1=1234567890123;
v2=mod(v1,10**10);
put v1= best32. v2=;
run;

```

Xia Keshan

SAS Employee
Posts: 8

## Re: =RIGHT(X,10) EXCEL STYLE FUNCTION ON SAS

Hi Xia,

It is character type.

I modified your code and it became this.

data test;

v1='1234567890123';

v2=put(mod(v1,10**10),10.);

run;

 v1 v2 1234567890123 4567890123

Now, I've had what I need.

Olp

Solution
‎10-25-2014 08:56 AM
Super User
Posts: 10,787

## Re: =RIGHT(X,10) EXCEL STYLE FUNCTION ON SAS

No. if it is character. I would write this.

data test;

v1='1234567890123';

v2=substr(strip(v1),length(v1)-9);

put v1= v2= ;

run;

Xia Keshan

Posts: 3,215

## Re: =RIGHT(X,10) EXCEL STYLE FUNCTION ON SAS

Yep as character is better for substr, The precision better said limits to precision will cause nice effects expected above 12 digits, sure above 15 digits.

---->-- ja karman --<-----
🔒 This topic is solved and locked.