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);
Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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