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

I am trying to figure out a way to print out all observations after a certain number of units has been reached. As an example:

Row      Member     Units     Date

1          A               4          1/1/2015

2          B               3          1/1/2015

3          A               3          1/5/2015    

4          A               3          1/6/2015

5          B               8          1/8/2015

6          A               6          1/11/2015    

For this example, I would like all rows/observations printed out once a unique member has reached over 10 units. Dates have been sorted because the interest is in how many observations and types of observations there are after 10 units has been reached. .

So the output should be:

Row      Member     Units     Date

1          A               6           1/11/2015

2          B               8           1/8/2015

Any help in figuring out how to determine the output would be appreciated!

As an aside, I am able to determine the total number of units and number of members > 10 units with:

proc sql ;

select member, sum(units) as totalunits ;

from data

group member

having totalunits > 10 ;

run ;

1 ACCEPTED SOLUTION

Accepted Solutions
naveen_srini
Quartz | Level 8

data have;
input Member $    Units     Date :mmddyy10.;
format  date mmddyy10.;
datalines;
           A               4          1/1/2015

        B               3          1/1/2015

          A               3          1/5/2015    
          A               3          1/6/2015

          B               8          1/8/2015

          A               6          1/11/2015    
    ;

proc sort data= have out=have1;
by member date;
run;

data want;
sum=0;

do until(last.member);
  set have1;
  by member;
  sum+units;

  if sum>10 then
   output;
end;

drop sum;
run;

Regards,

Naveen Srinivasan

L&T Infotech

View solution in original post

3 REPLIES 3
naveen_srini
Quartz | Level 8

data have;
input Member $    Units     Date :mmddyy10.;
format  date mmddyy10.;
datalines;
           A               4          1/1/2015

        B               3          1/1/2015

          A               3          1/5/2015    
          A               3          1/6/2015

          B               8          1/8/2015

          A               6          1/11/2015    
    ;

proc sort data= have out=have1;
by member date;
run;

data want;
sum=0;

do until(last.member);
  set have1;
  by member;
  sum+units;

  if sum>10 then
   output;
end;

drop sum;
run;

Regards,

Naveen Srinivasan

L&T Infotech

johnjinkim
Obsidian | Level 7

What if I were interested in only outputting observations after 5 dates of service (regardless of units)?

So only the following row should print out:

A           6      1/11/2015
naveen_srini
Quartz | Level 8

Sorry for the late response as I haven't been active here. "Regardless of units" or is regardless of member sort? I am asking this to make proper business sense. There is only 4 service dates for member A.

Anyway taking the notsorted "have" , a super simple logic below should suffice:

data have;
input Member $    Units     Date :mmddyy10.;
format  date mmddyy10.;
datalines;
           A               4          1/1/2015
        B               3          1/1/2015

          A               3          1/5/2015    
          A               3          1/6/2015

          B               8          1/8/2015

          A               6          1/11/2015    
    ;
data want;
set have;

if mod(_n_,6)=0 then
  output;
run;

Naveen Srinivasan

L&T Infotech

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
  • 3 replies
  • 695 views
  • 1 like
  • 2 in conversation