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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.