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
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.