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_id | facility_id | record_date | cure_count |
1 | 1 | 1/1/2001 | 1 |
1 | 2 | 1/1/2001 | 2 |
1 | 3 | 1/1/2001 | 3 |
1 | 1 | 2/1/2001 | 4 |
1 | 2 | 2/1/2001 | 5 |
1 | 3 | 2/1/2001 | 6 |
Here is what I want:
power_id | facility_id | record_date | cure_count |
1 | 1 | 1/1/2001 | 1 |
1 | 2 | 1/1/2001 | 1 |
1 | 3 | 1/1/2001 | 1 |
1 | 1 | 2/1/2001 | 2 |
1 | 2 | 2/1/2001 | 2 |
1 | 3 | 2/1/2001 | 2 |
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;
Do cure_count+1; only when facility_id = 1?
I'm not sure I understand your solution. This is for a table that has millions of power_id's and facility_id's.
Hi,
data want;
set have;
by power_id facility_id;
retain cure_count;
if first.factility_id then sum(cure_count,1);
run;
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.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.