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

 Hi All,

 

I have the dataset below which gives me details of account conversions at a sub account level.

 

data have;
	input account_id $ Sub_no $ reporting_date conversion_date;
	informat reporting_date conversion_date date9.;
	format reporting_date conversion_date date9.;
	
	cards;
	12345 1 31JAN2018 .
	12345 2 31JAN2018 .
	12345 3 31JAN2018 .
	67891 1 31JAN2018 .
	67891 2 31JAN2018 .
	12345 1 28FEB2018 28FEB2018
	12345 2 28FEB2018.
	12345 3 28FEB2018 .
	67891 1 28FEB2018 .
	67891 2 28FEB2018 28FEB2018
	;
run;


 

What I need is to aggregate this data to show the below

 

Account_IDReporting DateConversion_Date
1234531-Jan-18.
6789131-Jan-18.
1234528-Feb-1828-Feb-18
6789128-Feb-1828-Feb-18

 

I need to view 1 record per account number and reporting date irrespective of number of sub accounts the data has been aggregated from.

 

 

Many Thanks

 

Adnan

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Two approaches, SQL and data step, that produce the same result:

data have;
input account_id $ Sub_no $ reporting_date conversion_date;
informat reporting_date conversion_date date9.;
format reporting_date conversion_date date9.;
cards;
12345 1 31JAN2018 .
12345 2 31JAN2018 .
12345 3 31JAN2018 .
67891 1 31JAN2018 .
67891 2 31JAN2018 .
12345 1 28FEB2018 28FEB2018
12345 2 28FEB2018.
12345 3 28FEB2018 .
67891 1 28FEB2018 .
67891 2 28FEB2018 28FEB2018
;
run;

proc sql;
create table want1 as
select account_id, reporting_date, max(conversion_date) as conversion_date format=date9.
from have
group by reporting_date, account_id;
quit;

data want2;
set have (rename=(conversion_date=_cvdate));
by reporting_date account_id;
retain conversion_date;
format conversion_date date9.;
if _cvdate ne . then conversion_date = _cvdate;
if last.account_id then output;
drop _cvdate sub_no;
run;

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

PROC SUMMARY will do this

 

UNTESTED CODE

proc summary data=have;
    class account_id;
    var reporting_date conversion_date;
    output out=want min=;
run;
--
Paige Miller
Kurt_Bremser
Super User

Two approaches, SQL and data step, that produce the same result:

data have;
input account_id $ Sub_no $ reporting_date conversion_date;
informat reporting_date conversion_date date9.;
format reporting_date conversion_date date9.;
cards;
12345 1 31JAN2018 .
12345 2 31JAN2018 .
12345 3 31JAN2018 .
67891 1 31JAN2018 .
67891 2 31JAN2018 .
12345 1 28FEB2018 28FEB2018
12345 2 28FEB2018.
12345 3 28FEB2018 .
67891 1 28FEB2018 .
67891 2 28FEB2018 28FEB2018
;
run;

proc sql;
create table want1 as
select account_id, reporting_date, max(conversion_date) as conversion_date format=date9.
from have
group by reporting_date, account_id;
quit;

data want2;
set have (rename=(conversion_date=_cvdate));
by reporting_date account_id;
retain conversion_date;
format conversion_date date9.;
if _cvdate ne . then conversion_date = _cvdate;
if last.account_id then output;
drop _cvdate sub_no;
run;

sas-innovate-2024.png

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.

 

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
  • 2 replies
  • 1889 views
  • 0 likes
  • 3 in conversation