🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 02-27-2020 05:26 AM
(1966 views)
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
But in that new variables blank place we want zero's please modify that programme
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data want;
set ds;
pos=0; neg=0;
if amt >= 0 then pos=amt;
else neg=amt;
run;