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. 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2466 views
  • 0 likes
  • 2 in conversation