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);
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 29981 views
  • 3 likes
  • 7 in conversation