BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mohan_Reddy
Obsidian | Level 7
I have dataset like below....



data ds;

input id amt;

datalines;

1 40

3 20

4 -10

5 -30

2 50

6 -20

;

run;


Through this dataset i want to create output dataset have two new variables and one variable contains positive values only and another variable have negative values only...

If anyone knows please write a programme ....
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Do like this

 

data ds;
input id amt;
datalines;
1 40
3 20
4 -10
5 -30
2 50
6 -20
;
run;

data want;
    set ds;
    if amt >= 0 then pos=amt;
    else             neg=amt;
run;

 

Result:

 

id  amt  pos  neg 
1   40   40   . 
3   20   20   . 
4   -10  .    -10 
5   -30  .    -30 
2   50   50   . 
6   -20  .    -20 

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Do like this

 

data ds;
input id amt;
datalines;
1 40
3 20
4 -10
5 -30
2 50
6 -20
;
run;

data want;
    set ds;
    if amt >= 0 then pos=amt;
    else             neg=amt;
run;

 

Result:

 

id  amt  pos  neg 
1   40   40   . 
3   20   20   . 
4   -10  .    -10 
5   -30  .    -30 
2   50   50   . 
6   -20  .    -20 
Mohan_Reddy
Obsidian | Level 7
But in that new variables blank place we want zero's please modify that programme
PeterClemmensen
Tourmaline | Level 20
data want;
    set ds;
    pos=0; neg=0;
    if amt >= 0 then pos=amt;
    else             neg=amt;
run;

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 25. 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
  • 1816 views
  • 1 like
  • 2 in conversation