Hi,
I have following data i need count of first three obs in fourth obs with var as tot and count of next three(5,6,7) in obs 8 as var tot
eg:
obs var cnt
1 eg 3
2 eg 4
3 eg 5
4 tot 12
5 rt 3
6 rt 4
7 rt 1
8 tot 8
I'm guessing this is what you want..
data have;
input var $ cnt;
datalines;
eg 3
eg 4
eg 5
rt 3
rt 4
rt 1
;
data want(drop=s);
do _n_=1 by 1 until (last.var);
set have;
by var notsorted;
s+cnt;
output;
end;
var='tot';cnt=s;
output;
s=0;
run;
Is this for reporting purposes or do you want a new data set like this?
Hi,
i want data set like these
Thanks
I'm guessing this is what you want..
data have;
input var $ cnt;
datalines;
eg 3
eg 4
eg 5
rt 3
rt 4
rt 1
;
data want(drop=s);
do _n_=1 by 1 until (last.var);
set have;
by var notsorted;
s+cnt;
output;
end;
var='tot';cnt=s;
output;
s=0;
run;
Thank you
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.