BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Santt0sh
Lapis Lazuli | Level 10

Hi All,

 

I trying to send emails to different users, i have written two SAS macros let's say Macro A, and Macro B.

for certain reasons i am not able to share the code here as i am working on secured network, but I will try my best to explain what the two macro do.

Macro A.: Macro creates a table for each department (i.e. Dept A, B ,C) the macro creates the Subset of data from the  Repository for the mentioned period. which will extract the details of the Sales, location, Product and user details like Name of the user, email id.

 

Macro B: Macro creates the intermediate tables which will have details of the user, and his Sales data viz, Sales for each location summaries the data for each salesperson, for each location he is responsible. and emails the information to him and his manager.

 

when i am running the the SAS Macro for Dept A, Dept B and Dept C individually i am able to get the desired results.

for ex. 

Dept A has 2 sales done by Salesperson XYZ, the Salesperson and his manager is receiving emails for the 2 sales made by him for the Week.

 

Similarly Dept B has 1 Sales done by Salesperson ABC the  Salesperson and his manager is receiving emails for the 1 sale made by him for the Week.

Similarly Dept c has 10 Sales done by Salesperson UVW the Salesperson and his manager is receiving emails for the 10 sales made by him for the Week.

 

Only 3 emails sent for each sale. for the week.

I am able to achieve this by running both Macro and Macro B for each Dept, But when i am running it for all the 3 Dept(A,B,C) ii am getting as many as 12 emails. instead of 3 emails.

 

 Execution: Macro execution order

Macro A; to create the Subset for each dept, 

and Macro B is called within Macro A, in order to send emails to the Salesperson who has made sales.

 

Could you please suggest me how to Run for all the departments and send emails, as this will run in a Batch in prod environment?

 

Regards,

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

1. Make fake data

2. Modify your code to work with the fake data

3. Post it here so we can help with more information. 

 

It's hard to say what's wrong with your code if we can't see it.

 

 


@Santt0sh wrote:

Hi All,

 

I trying to send emails to different users, i have written two SAS macros let's say Macro A, and Macro B.

for certain reasons i am not able to share the code here as i am working on secured network, but I will try my best to explain what the two macro do.

Macro A.: Macro creates a table for each department (i.e. Dept A, B ,C) the macro creates the Subset of data from the  Repository for the mentioned period. which will extract the details of the Sales, location, Product and user details like Name of the user, email id.

 

Macro B: Macro creates the intermediate tables which will have details of the user, and his Sales data viz, Sales for each location summaries the data for each salesperson, for each location he is responsible. and emails the information to him and his manager.

 

when i am running the the SAS Macro for Dept A, Dept B and Dept C individually i am able to get the desired results.

for ex. 

Dept A has 2 sales done by Salesperson XYZ, the Salesperson and his manager is receiving emails for the 2 sales made by him for the Week.

 

Similarly Dept B has 1 Sales done by Salesperson ABC the  Salesperson and his manager is receiving emails for the 1 sale made by him for the Week.

Similarly Dept c has 10 Sales done by Salesperson UVW the Salesperson and his manager is receiving emails for the 10 sales made by him for the Week.

 

Only 3 emails sent for each sale. for the week.

I am able to achieve this by running both Macro and Macro B for each Dept, But when i am running it for all the 3 Dept(A,B,C) ii am getting as many as 12 emails. instead of 3 emails.

 

 Execution: Macro execution order

Macro A; to create the Subset for each dept, 

and Macro B is called within Macro A, in order to send emails to the Salesperson who has made sales.

 

Could you please suggest me how to Run for all the departments and send emails, as this will run in a Batch in prod environment?

 

Regards,

 

 


 

View solution in original post

7 REPLIES 7
Reeza
Super User

1. Make fake data

2. Modify your code to work with the fake data

3. Post it here so we can help with more information. 

 

It's hard to say what's wrong with your code if we can't see it.

 

 


@Santt0sh wrote:

Hi All,

 

I trying to send emails to different users, i have written two SAS macros let's say Macro A, and Macro B.

for certain reasons i am not able to share the code here as i am working on secured network, but I will try my best to explain what the two macro do.

Macro A.: Macro creates a table for each department (i.e. Dept A, B ,C) the macro creates the Subset of data from the  Repository for the mentioned period. which will extract the details of the Sales, location, Product and user details like Name of the user, email id.

 

Macro B: Macro creates the intermediate tables which will have details of the user, and his Sales data viz, Sales for each location summaries the data for each salesperson, for each location he is responsible. and emails the information to him and his manager.

 

when i am running the the SAS Macro for Dept A, Dept B and Dept C individually i am able to get the desired results.

for ex. 

Dept A has 2 sales done by Salesperson XYZ, the Salesperson and his manager is receiving emails for the 2 sales made by him for the Week.

 

Similarly Dept B has 1 Sales done by Salesperson ABC the  Salesperson and his manager is receiving emails for the 1 sale made by him for the Week.

Similarly Dept c has 10 Sales done by Salesperson UVW the Salesperson and his manager is receiving emails for the 10 sales made by him for the Week.

 

Only 3 emails sent for each sale. for the week.

I am able to achieve this by running both Macro and Macro B for each Dept, But when i am running it for all the 3 Dept(A,B,C) ii am getting as many as 12 emails. instead of 3 emails.

 

 Execution: Macro execution order

Macro A; to create the Subset for each dept, 

and Macro B is called within Macro A, in order to send emails to the Salesperson who has made sales.

 

Could you please suggest me how to Run for all the departments and send emails, as this will run in a Batch in prod environment?

 

Regards,

 

 


 

Santt0sh
Lapis Lazuli | Level 10

Sample Macro:

libname mydblib oracle user=testuser password=testpass path=hrdept_002;

%macro A(dsn=,dept=);

data &dsn.;

set mylibdb. sales_rep;

where department = &dept and salesdate = today() - intnx('day',today(),-7);

run;

 

< Summarisation of the sales data>

    %B(Sales_A,abc,));

%mend;

 

%macro B(dsn,slesp);

 

Creation of Macro variables and to Send emails to the Salesperson and his Manager.

 

%mend;

%A(dept = Sales_A, Dept=A);

 

Reeza
Super User

Sorry, that's not enough information for me to help, I can't run it or see where the issues may be.

Hopefully someone else will be able to help you shortly. 

 


@Santt0sh wrote:

Sample Macro:

libname mydblib oracle user=testuser password=testpass path=hrdept_002;

%macro A(dsn=,dept=);

data &dsn.;

set mylibdb. sales_rep;

where department = &dept and salesdate = today() - intnx('day',today(),-7);

run;

 

< Summarisation of the sales data>

    %B(Sales_A,abc,));

%mend;

 

%macro B(dsn,slesp);

 

Creation of Macro variables and to Send emails to the Salesperson and his Manager.

 

%mend;

%A(dept = Sales_A, Dept=A);

 


 

Santt0sh
Lapis Lazuli | Level 10
Hi Reeza,

Thank you for you quick reply. I will try and recreate the issue and post the Code here.

Thanks
Astounding
PROC Star

In the code that you are not showing ...

 

Are you using SQL to join data sets?

 

Do you understand what a Cartesian product is?

Santt0sh
Lapis Lazuli | Level 10
Hi,
Yes I am using proc sql to join tables, and I am using left join the resulting table is as expected. And I don’t see any Cartesian product.


Astounding
PROC Star

Left join will handle mismatches, but it still leaves open the possibility of a Cartesian product.  Consider this data:

 

Data Set A

ID  A_Value

1    A1

1    A2

 

Data Set B

ID  B_Value

1    B1

1    B2

1    B3

 

You can join these any way you want (left, right, inner) matching on ID.  You will always get 6 observations.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 7 replies
  • 2342 views
  • 1 like
  • 3 in conversation