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

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
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

5 REPLIES 5
LinusH
Tourmaline | Level 20

Do cure_count+1; only when facility_id = 1?

Data never sleeps
Steelers_In_DC
Barite | Level 11

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

data want;

     set have;

     by power_id facility_id;

     retain cure_count;

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

run;

LinusH
Tourmaline | Level 20

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
Tom
Super User Tom
Super User

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;

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
  • 5 replies
  • 1298 views
  • 0 likes
  • 4 in conversation