BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
kyle234
Obsidian | Level 7
For the the numeric variable num=10.9 I want the 9 in a variable. If the number is 10.78 I want 78 in a variable.

Thank you!
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Can you explain what you are doing?  Why do you need the digits after the period as a separate variable?  How many digits do you need?  What do want for a number like 1/3 that cannot be represented exactly in as a decimal fraction?  Do you want 3? 33? 333? 3333?  If you want 2 digits why do you want 10.9 to be 9 instead of 90?  

 

If you just want the remainder use the MOD() function.

remainder = mod(NUM,1);

That will get you .9 and .78 for your two examples.  You could multiply by 100 to get 90 and 78 instead.

 

If you just want the string then convert the number into (back into?) a string and use string functions.  So assuming you want two digits after the decimal place you might do something like:

string=scan(put(NUM,32.2),2,'.');

But that will get you '90' and '78' for your examples.  To get '9' and '78' use BEST32. instead as the format in the PUT() function call.

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Can you explain what you are doing?  Why do you need the digits after the period as a separate variable?  How many digits do you need?  What do want for a number like 1/3 that cannot be represented exactly in as a decimal fraction?  Do you want 3? 33? 333? 3333?  If you want 2 digits why do you want 10.9 to be 9 instead of 90?  

 

If you just want the remainder use the MOD() function.

remainder = mod(NUM,1);

That will get you .9 and .78 for your two examples.  You could multiply by 100 to get 90 and 78 instead.

 

If you just want the string then convert the number into (back into?) a string and use string functions.  So assuming you want two digits after the decimal place you might do something like:

string=scan(put(NUM,32.2),2,'.');

But that will get you '90' and '78' for your examples.  To get '9' and '78' use BEST32. instead as the format in the PUT() function call.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 488 views
  • 1 like
  • 2 in conversation