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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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