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.
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?
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.
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;
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?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.