SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
EG_Mel
Calcite | Level 5
I need to convert a column of numbers to the opposite signs (positive to negative and negative to positive). I have been able to set up a computed column using the case function. However some of the values are zeros and nulls and these are coming out as "1". Any ideas or other functions I could use?

Thanks!
8 REPLIES 8
Doc_Duke
Rhodochrosite | Level 12
Just multiply by -1 .
Peter_C
Rhodochrosite | Level 12
- (minus) can be a "unary operator", like [pre] fall = - rise ; [/pre] It is also referred to as a "prefix operator" in the doc at http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000780367.htm .

PeterC
durgeshrpatil
Calcite | Level 5
Could you please share in the code
PaigeMiller
Diamond | Level 26

@durgeshrpatil  The code has been provided earlier in this thread.

--
Paige Miller
Doc_Duke
Rhodochrosite | Level 12
If the var is called "x", then

x = -x;

changes the sign and you don't create a new variable. In the context of an assignment statement (data step), "=" means "assign the value of the expression on the right to the variable on the left". Similar to the SQL 'as' clause.
lalohg
Quartz | Level 8

how can I convert the negative numbers to positive only without changing positive numbers?

 

your help will be appreciated

 

Thanks

ChrisHemedinger
Community Manager

@lalohg You mean, take the absolute value?  Use the ABS() function:

 

x = abs(x);
Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 8 replies
  • 31947 views
  • 3 likes
  • 7 in conversation