BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Vijay77
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Is this for reporting purposes or do you want a new data set like this?

Vijay77
Fluorite | Level 6

Hi,

   i want data set like these 

 

Thanks

PeterClemmensen
Tourmaline | Level 20

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;
Vijay77
Fluorite | Level 6

Thank you

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1145 views
  • 0 likes
  • 2 in conversation