- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
--------------------------