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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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