BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
o_p
SAS Employee o_p
SAS Employee

Hi,

How can the below excel function coded in SAS?

VAR01

VAR02

1234567890123=RIGHT(A2,10)

The result must be "4567890123".

Thanks,

Olp

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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

View solution in original post

5 REPLIES 5
jakarman
Barite | Level 11

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 --<-----
Ksharp
Super User

It was character type or numeric type ?

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



Xia Keshan

o_p
SAS Employee o_p
SAS Employee

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;

v1v2
12345678901234567890123

Now, I've had what I need.

Thanks for your quick answer.

Olp

Ksharp
Super User

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

jakarman
Barite | Level 11

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 --<-----

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 9182 views
  • 7 likes
  • 3 in conversation