BookmarkSubscribeRSS Feed
MagD
Quartz | Level 8

Hi All,

 

Please assist me. I am trying to get all variables only at 2 points, at the earliest date (LTPR1) and at the latest date (LTPR2). I have millions of records with different starting and end dates.

Current data:

Arrears Balance Instalemt CD Lifetime Lifetime Period LTPR1 LTPR12
-17 7400.61 323 0 A 201911 201910 202004
-391 6380.61 323 -1 A 202001 201910 202004
-340 7400.61 323 -1 A 201910 201910 202004
-68 6057.61 323 0 C 202003 201910 202004
-384 6710.61 323 -1 A 201912 201910 202004
-68 6380.61 323 0 D 202002 201910 202004
259.64 6062.25 323 1 8 202004 201910 202004

 

Desired output:

ID_Number Arrears @1 Arrears @12 Balance @ 1 Balance @ 12 CD @ 1 CD @ 12 Lifetime @ 1 Lifetime @ 12 Lifetime Period @ 1 Lifetime Period @ 12 LTPR1 LTPR12
12345678910 -340 259.64 7400.61 6062.25 -1 1 A 8 201910 202004 201910 202004

 

 

This is the code I currently have:

proc sql;
create table Sub2
as select *, min('Lifetime Payment Rating Finmonth'n) as LTPR1, max('Lifetime Payment Rating Finmonth'n) AS LTPR12
from Variables
where Sub = 2 and Income_Doc_Type is not null
group by ID_Number
having Nett_Monthly_Income = max(Nett_Monthly_Income)
and ID_Number=max(ID_Number);
run;

1 REPLY 1
RichardDeVen
Barite | Level 11

You can self merge where selected rows by ID, renaming the columns as desired.

 

Example:

data have;
id = '123456';
input 
Arrears Balance Instalemt CD Lifetime $ Lifetime_Period LTPR1    LTPR12;
datalines;
-17    7400.61    323    0    A    201911    201910    202004
-391   6380.61    323   -1    A    202001    201910    202004
-340   7400.61    323   -1    A    201910    201910    202004
-68    6057.61    323    0    C    202003    201910    202004
-384   6710.61    323   -1    A    201912    201910    202004
-68    6380.61    323    0    D    202002    201910    202004
259.64 6062.25    323    1    8    202004    201910    202004
;


data want;
  attrib
    id         length = $10
    arrears1   label = "Arrears @1"
    arrears12  label = "Arrears @12"
    balance1   label = "Balance @1"
    balance12  label = "Balance @12"
    cd1        label = "CD @1"
    cd12       label = "CD @12"
    lifetime1  label = "Lifetime @1"
    lifetime12 label = "Lifetime @12"
    lifetime_period1  label = "Lifetime Period @1"
    lifetime_period12 label = "Lifetime Period @12"
  ;
  merge
    have (where=(lifetime_period1=ltpr1)
      rename = (
        arrears   = arrears1
        balance   = balance1
        cd        = cd1
        lifetime  = lifetime1
        lifetime_period = lifetime_period1
      )
      drop = instalemt
    )
    have (where=(lifetime_period12=ltpr12)
      rename = (
        arrears   = arrears12
        balance   = balance12
        cd        = cd12
        lifetime  = lifetime12
        lifetime_period = lifetime_period12
      )
      drop = instalemt
    )
  ;
  by id ltpr1 ltpr12;
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 878 views
  • 0 likes
  • 2 in conversation