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 2025: Call for Content

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!

Submit your idea!

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.

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