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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.