set counter

Accepted Solution Solved
Reply
Valued Guide
Posts: 854
Accepted Solution

set counter

I am using a counter like this:

data test;

set data;

by power_id record_date;

cure_count+1;

if first.power_id then count= 1;

if default ne '' then count= 0;

There is a facility_id that roles up to power_id.  Is there a way to keep facility_id in this dataset but not count by it?

Here is what I have:

power_idfacility_idrecord_datecure_count
111/1/20011
121/1/20012
131/1/20013
112/1/20014
122/1/20015
132/1/20016

Here is what I want:

power_idfacility_idrecord_datecure_count
111/1/20011
121/1/20011
131/1/20011
112/1/20012
122/1/20012
132/1/20012

Accepted Solutions
Solution
‎02-13-2015 10:26 AM
Super User
Super User
Posts: 6,373

Re: set counter

Why did you bump the counter when you did?  Was it because of the change in date?

data want ;

  set have ;

  by power_id record_date ;

  if first.power_id then cure_count=0;

  if first.record_date then cure_count+1;

run;

View solution in original post


All Replies
Esteemed Advisor
Posts: 5,202

Re: set counter

Do cure_count+1; only when facility_id = 1?

Data never sleeps
Valued Guide
Posts: 854

Re: set counter

I'm not sure I understand your solution.  This is for a table that has millions of power_id's and facility_id's.

Esteemed Advisor
Esteemed Advisor
Posts: 7,251

Re: set counter

Hi,

data want;

     set have;

     by power_id facility_id;

     retain cure_count;

     if first.factility_id then sum(cure_count,1);

run;

Esteemed Advisor
Posts: 5,202

Re: set counter

From you sample it looked like facility restarts its count, each date? Your sample may not represent the real complexity.

Perhaps you could use first.record_date instead.

Data never sleeps
Solution
‎02-13-2015 10:26 AM
Super User
Super User
Posts: 6,373

Re: set counter

Why did you bump the counter when you did?  Was it because of the change in date?

data want ;

  set have ;

  by power_id record_date ;

  if first.power_id then cure_count=0;

  if first.record_date then cure_count+1;

run;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 249 views
  • 0 likes
  • 4 in conversation