arraysloopssasstacked

SAS Array question each data subject has multiple rows


My data is structured Monthly, on each month an update is added to each customers record. these are stacked vertically. I want to search through each customer if a flag or indicator appears in any month I want to record that permanently. From my example if there is ever a missed payment I want the ever_missed flag to always be 1

|Cust Id| |Month| |missed_pay| |ever_missed|

1234 Jan 0
1234 Feb 0
1234 Mar 1
1234 Apr 0
5678 Jan 1
5678 Feb 0
5678 Mar 1
5678 Apr 0

I have been looking at array tutorials but generally the dates etc are horizontal

Jan Feb Mar.

essentially all i want to do is loop through each record per customer and if missed_pay = 1 then ever_missed = 1


Solution

  • This could be done in a DATA step with "DOW loop", but SAS PROC SQL makes it easy, because of the "remerging" feature. I don't think arrays would be helpful for this.

    data have ;
      input Cust_ID Month $3. missed_pay ;
      cards ;
    1234 Jan 0
    1234 Feb 0
    1234 Mar 1
    1234 Apr 0
    5678 Jan 1
    5678 Feb 0
    5678 Mar 1
    5678 Apr 0
    9999 Jan 0
    9999 Feb 0
    9999 Mar 0
    9999 Apr 0
    ;
    
    proc sql ;
      create table want as
      select *,max(missed_pay) as ever_missed
      from have
      group by Cust_ID
      ;
    quit ;
    
    proc print data=want ;
    run ;