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 ....
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
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
data want;
set ds;
pos=0; neg=0;
if amt >= 0 then pos=amt;
else neg=amt;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.