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
What are common programming errors committed in sas
What is the purpose of _character_ and _numeric_?
How do you define proc in sas? : sas-grid-administration
what is the difference between: x=a+b+c+d; and x=sum (of a, b, c ,d);? : Sas programming
What is the use of stop statement?
explain about data integrator metadata reports? : Sas-di
do you prefer proc report or proc tabulate? Why? : Sas programming
If a variable contains only numbers, can it be a character data type?
Differences between where and if statement?
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;
Can you suggest us materials for sdtm mapping?
for what purpose would you use the retain statement? : Sas programming
What do you know about symput and symget?
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.
How to limit decimal places for variable using proc means?