turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- SAS Function to check whether the field value is d...

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-18-2015 10:08 AM

Hi,

Is there a SAS fucntion to check whether the field value is numeric or decimal. Please anyone can advise?

Regards,

Siva

Accepted Solutions

Solution

08-18-2015
11:35 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to sivaram_veerabagu

08-18-2015 11:35 AM

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to sivaram_veerabagu

08-18-2015 10:26 AM

Can you explain more and give an example? Do you mean integer values versus having a decimal part?

If so, you can test whether int(x)=x.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

08-18-2015 11:20 AM

Hi Rick,

For e.g If I have the values for the column in the dataset as follows.

TOTAL_SUM

156

134.67

147

190.00

I need to find if the value of TOTAL_SUM is decimal then I have to do some manipulation based on that?

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to sivaram_veerabagu

08-18-2015 11:27 AM

What is your definition of decimal? What manipulation do you need to do? What do you want your output to look like?

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

08-18-2015 11:30 AM

Hi Reeza,

For e.g If have a decimal point(.) in the value then I would like to multiply only those value with 100.

Regards,

Siva

Solution

08-18-2015
11:35 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to sivaram_veerabagu

08-18-2015 11:35 AM

if int(TOTAL_SUM) ^= TOTAL_SUM then

TOTAL_SUM = TOTAL_SUM*100;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to sivaram_veerabagu

08-18-2015 11:35 AM

Hi Reeza,

For e.g the following decimal values have to be multiplied by 100.

134.67 -> 134.67 *100 -> 13467

Regards,

Siva

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to sivaram_veerabagu

08-18-2015 11:58 AM

Thanks Rick

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to sivaram_veerabagu

08-18-2015 11:43 AM

Irrespective of the number of decimal places,if you want to multiply the number with 100 then you can use the following code.

data Want;

input Total_Sum;

if scan(Total_Sum,2,'.') ne " " then Total_Sum=Total_Sum*100;

cards;

156

134.67

147

190.00

;

If there is condition on which the number should be multiplied basing on the number of decimal places(i.e multiply with 100 if the value has two decimal places and 10 for 1 decimal place ....) then you can use the following code

data Want;

input Total_Sum;

if lengthn(scan(Total_Sum,2,'.')) ge 2 then Total_Sum=Total_Sum*100;

if lengthn(scan(Total_Sum,2,'.')) eq 1 then Total_Sum=Total_Sum*10;

cards;

156

156.1

134.67

147

190.00

;