BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aanan1417
Quartz | Level 8

data have;

input number;

-100

-200

100

200

;

run;

using data have .i want to create two variable one with positive value  and other with negative value  

output should be like

negative         positive 

-100               100

-200                200

 

 

Edit: nondescriptive subject line ("sas"!) changed by KB.

 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

You apparently want to merge the first positive number with the first negative, the second positive with the second negative, etc.

In addition to @Rick_SAS 's question about what you want to do with zeroes, what to you want to do with excess positives or excess negative?

 

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

Use the ABS() function to get the absolute value for positive, and multiply it with -1 to get the negative.

 

PS you were asked for a descriptive subject line when posting the question. "sas" is not descriptive, it's simply stupid when posting in the SAS Communities.

Rick_SAS
SAS Super FREQ

Your DATA step is missing a DATALINES statement.

You don't say what you want to happen if the data contains 0, but here is one approach. I assume you want all the positive values to be in one column and all negative values to be in another column:

 

data Have;
input number;
datalines;
-100
-200
10
20
57
-43
-64
0
;

data Pos Neg;
set Have;
if      number > 0 then output Pos;
else if number < 0 then output Neg;
else put "Warning: 0 was found";
run;

data Want;
merge Pos(rename=(Number=Positive)) 
      Neg(rename=(Number=Negative));
run;

proc print; run;

 

mkeintz
PROC Star

You apparently want to merge the first positive number with the first negative, the second positive with the second negative, etc.

In addition to @Rick_SAS 's question about what you want to do with zeroes, what to you want to do with excess positives or excess negative?

 

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 10545 views
  • 2 likes
  • 4 in conversation