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

What are common programming errors committed in sas

674


What is the purpose of _character_ and _numeric_?

589


How do you define proc in sas? : sas-grid-administration

676


what is the difference between: x=a+b+c+d; and x=sum (of a, b, c ,d);? : Sas programming

609


What is the use of stop statement?

644






explain about data integrator metadata reports? : Sas-di

565


do you prefer proc report or proc tabulate? Why? : Sas programming

574


If a variable contains only numbers, can it be a character data type?

613


Differences between where and if statement?

584


i have a dataset with 100 obs i want to generate title from 20th obs onwards with total observations. that should contain 100 obs.dont use firstobs and dnt split the data. use dataset block or proc report? how can we genarate;

1973


Can you suggest us materials for sdtm mapping?

4039


for what purpose would you use the retain statement? : Sas programming

585


What do you know about symput and symget?

731


data data1; input dt account; format dt date9.; cards; 1745 1230 1756 1120 1788 1130 1767 1240 ; data data2; input startdt enddt total; format startdt date9. enddt date9.; cards; 1657 1834 12300 1557 1758 16800 1789 1789 12300 1788 1345 12383 1899 1899 13250 ; proc sql; create table data3 as select * from data1 as x left join data2 as y on x.dt>=y.startdt and x.dt<=y.enddt; quit; Here, we are getting cartision product. But,I want left join report consisting of this program. It should not get duplicate values. you can modify the program also.

1802


How to limit decimal places for variable using proc means?

590