how to add distinctly var variable values ex..
Data a;
input var;
datalines;
0
1
2
3
-1
-2
-3
;
run;
adding all +ve value in one varibale n do the same for -ve
too

Answer Posted / ashish

data a;
input num;
cards;
1
2
3
-5
-7
-8
9
10
0
-56
-3
;
run;
data b ;
retain sum_n sum_p;
set a end=last;

if _n_=1 then sum_n = 0;
if _n_=1 then sum_p = 0;
if(num<0) then sum_n= sum(sum_n,num);
else sum_p= sum(sum_p,num);
if last then output;
run;

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can I remove header from output data set?

2053


explain the proc in sas? : Sas-administrator

604


what is sas enterprise intelligence architecture? : Sas-bi

532


what is the effect of the options statement errors=1? : Sas programming

575


what is null hypothesis? why do you consider that?

2407






Do you need to know if there are any missing values?

586


it will become easy if uuu provide website linkssss and list of consultanciessssss

1519


Define run-group processing?

571


What is your favorite all time computer book? Why?

2038


What does proc print, and proc contents are used for?

601


What is PDV?

713


what is the difference between calculating the 'mean' using the mean function and proc means? : Sas programming

618


Name few SAS functions?

659


how do you debug and test your sas programs? : Sas programming

550


what is the use of sas management console? : Sas-di

603