BookmarkSubscribeRSS Feed
snaini
Calcite | Level 5

Hello fellow SAS programmers,

 

I am tring to create a report notification where a group of people get an email saying that they have purchased an item on so on date with a list of other induvuduals who have purchased the same/similar item.

 

Here is my table:

 

Purchase_IDPurchase_DateName PhoneEmail_Txt
1011/1/2016jon123You are getting this email because you have purchased this item on 01/01/2016
1011/2/2016smith456You are getting this email because you have purchased this item on 01/02/2016
2011/5/2016KAY789You are getting this email because you have purchased this item on 01/05/2016
2011/3/2016TOM654You are getting this email because you have purchased this item on 01/03/2016
2011/2/2016JILL741You are getting this email because you have purchased this item on 01/02/2016

 

I want to creat a report that will look like:

 

You are getting this email because you have purchased this item on 01/01/2016
     
Purchase_IDPurchase_DateName Phone 
1011/1/2016jon123 
1011/2/2016smith456 
     
You are getting this email because you have purchased this item on 01/02/2016
     
Purchase_IDPurchase_DateName Phone 
2011/5/2016KAY789 
2011/3/2016TOM654 
2011/2/2016JILL741 

 

My Code:

proc sort data=book3 out=temp101;
	by Purchase_ID EMAIL_TXT;
run;

options nobyline;

proc report data=temp101 nowd headline headskip wrap;
	by Purchase_ID EMAIL_TXT;
	column Purchase_Date Name Phone;
	define Purchase_Date/'Purchase Date';
	define Name/'Customer Name';
	define Phone/'Customer Phone';
	title1 justify=left "NOTIFICATION";
	title justify=left "#byval2";
run;
 

When I run the code, I am uinable to group records by Purchase_ID with title as EMAIL_TXT using the #byval.

 

Here is my output report:

You are getting this email because you have purchased this item on 01/01/2016

Purchase Date Customer Name Customer Phone
01JAN2016jon123

You are getting this email because you have purchased this item on 01/02/2016

Purchase Date Customer Name Customer Phone
02JAN2016smith456

You are getting this email because you have purchased this item on 01/02/2016

Purchase Date Customer Name Customer Phone
02JAN2016JILL741

You are getting this email because you have purchased this item on 01/03/2016

Purchase Date Customer Name Customer Phone
03JAN2016TOM654

You are getting this email because you have purchased this item on 01/05/2016

Purchase Date Customer Name Customer Phone
05JAN2016KAY789

 

 

Is there a way I can group all records under one Purchase_ID with EMAIL_TXT as Title?

 

Any help will be much appreciated!

 

Thanks in advance

 

 

1 REPLY 1
SuzanneDorinski
Lapis Lazuli | Level 10

The EMAIL_TXT in your data varies for each record within a PURCHASE_ID.  That's why you see jon and smith listed separately, even though they both have the same PURCHASE_ID. 

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
  • 1 reply
  • 1929 views
  • 0 likes
  • 2 in conversation