## Convert positive number to negative and negative to positive

Occasional Learner
Posts: 1

# Convert positive number to negative and negative to positive

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!
Posts: 2,121

## Re: Convert positive number to negative and negative to positive

Just multiply by -1 .
Valued Guide
Posts: 2,190

## Re: Convert positive number to negative and negative to positive

- (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
Posts: 2,121

## Re: Convert positive number to negative and negative to positive

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.
Contributor
Posts: 33

## Re: Convert positive number to negative and negative to positive

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

Thanks

Community Manager
Posts: 3,353

## Re: Convert positive number to negative and negative to positive

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

``x = abs(x);``
Contributor
Posts: 33