BookmarkSubscribeRSS Feed
sahoositaram555
Pyrite | Level 9

Hi all,

I have 2 columns such as below.

 

col1      col2

xxxxx  0.5

yyyyy   1

zzzz     1

kkkk     1

llllllll      1

xxxxx  1.5

yyyyy   2

zzzz     2

kkkk     2

llllllll      2

................. similarly i have values up to 60.

 

My COL2 is numeric, Looking for a procedure to find out to TAG the rows containing decimal values, the order can not be changed? (with out converting the column in to character and then using any function to pick the decmial) 

5 REPLIES 5
Reeza
Super User
So

decimal = floor(col2) - col2;
if decimal = 0 then .....now what??
PeterClemmensen
Tourmaline | Level 20

I'm not sure I follow. Are you looking to tag/flag non-integers?

ballardw
Super User

@sahoositaram555 wrote:

Hi all,

I have 2 columns such as below.

 

col1      col2

xxxxx  0.5

yyyyy   1

zzzz     1

kkkk     1

llllllll      1

xxxxx  1.5

yyyyy   2

zzzz     2

kkkk     2

llllllll      2

................. similarly i have values up to 60.

 

My COL2 is numeric, Looking for a procedure to find out to TAG the rows containing decimal values, the order can not be changed? (with out converting the column in to character and then using any function to pick the decmial) 


Basic approach is to see if the value when converted to an integer is equal to the original value. If so then there is no decimal, if there is a difference then there is a decimal portion to the value.

data want;
   set have;
   tag = (intz(col2) ne col2);
run;

SAS returns 1 for true and 0 for false. So the comparison above would be 1 when the decimal portion returned by the INTZ function is not equal to the original value.

Peter_C
Rhodochrosite | Level 12

the logic before programming in code seems to be

 if decimal present in col2 then ......

 

in base SAS code try finding something simpler that

   if mod( col2, 1 ) then do;

     * ~something ~ ;

    end;

 

 

Peter_C
Rhodochrosite | Level 12
perhaps
TAG = ^^mod( col2, 1 ) ;
where TAG should be 1 when there are decimals, and 0 when col2 is integer or missing

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1012 views
  • 3 likes
  • 5 in conversation