DATA Step, Macro, Functions and more

Help with data

Reply
Frequent Contributor
Posts: 127

Help with data

I have dataset with date and working day flag(1 is working and 0 means non-working day). Then

I have sales dataset with sales number and sales_date.  I have another dataset with Inventory number and  Inv_date.

What  I have to do is, check if everyday if current day is working day or not.   If it is working day then check if there are sales for today from Sales dataset and  Inventory for today from Inventory dataset, If  either Sales or Inventory or both conditions are not satisfied then send email through SAS saying that "Sales data is missing for today or Inventory data is missing or Both data are missing".

Any help in this will be greatly appreciated..

Regular Contributor
Posts: 217

Re: Help with data

pp2014,

What do you want sent in your email?  A file of errant info attached to the email; a list of errant info in a txt file attached to the email;  a line of text in the email itself for each errant row? The data can be analyzed wth a data step or sql step or something else.  Which do you prefer?  Are you emailing from your PC or a remote session such as a mainframe or unix or etc.?


Frequent Contributor
Posts: 127

Re: Help with data

I want to send the email saying that "Sales data and Inventory data missing"  /*** if both data are missing *********/ 

or

"Sales data is missing"  /*****if only sales data is missing  *******/

or

"Inventory data is missing"  /*****if only Inventory data is missing  *******/

I will be mailing from PC.    SAS running on Windows 7 environment.

Super User
Posts: 19,877

Re: Help with data

I'm assuming you're running this on a daily basis? Would it be checking for the same day or for the previous day?

Id also recommend checking the number of records vs the expected status.

Frequent Contributor
Posts: 127

Re: Help with data

I will be running it on daily basis and checking for the same day.   Yes I would check for records for that day so that I can send email based on which dataset has 0 records.

Regular Contributor
Posts: 217

Re: Help with data

SQL code can build, compare the three datasets and decide which &failed. condition exists.  When the SQL is complete, execute the macro.  There are also ways other than SQL to decide which of the three failed conditions exist.


%macro mailerr;
                    filename mymail email;                                                                                                                              

                    data _null_;                                                                                                                                           
                      file mymail                                                                                                                                          
       subject=(" Put your subject here ")                                                                                                                               
              TO=('firstname.lastname@address');
%if  &failed. = 1 %then %do;
                      put "    Sales data is missing        ";

%end;  
%if &failed. = 2  %then %do;                                                                         
                      put  "Inventory data is missing"        ;  

%end;    
%if &failed. = 3 %then %do;                                                                     
                      put   "Sales data and Inventory data missing"     ;    

%end;                                                                        
                    run; 
%mend mailerr;

Ask a Question
Discussion stats
  • 5 replies
  • 249 views
  • 0 likes
  • 3 in conversation