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);
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 32834 views
  • 3 likes
  • 7 in conversation