AFHood Group Blog The thoughtless yammerings of marketing junkies..

19Jul/100

Sending an email from SAS

Have you ever wanted to know when your code completes? Or maybe you want to automate the report to include sending an email?

Regardless, SAS is happy to send that email for you. The easiest way to do this is through the SMTP access method via filename statements.

Example:

filename sendemail email 'toaddress@email.com' subject='This is a test email.' from='fromaddress@email.com';

data _null_;

file sendemail;

put 'Hi,';

put 'This is a email sent from SAS';

run;

This is only a simple example. Here is another with an attachment.

filename sendemail email 'toaddress@email.com' subject='This is a test email.' from='fromaddress@email.com' attach='/somesascode.sas';

data _null_;

file sendemail;

put 'Hi,';

put 'This is a email sent from SAS';

run;

Email attributes can also be set in the data step through the EM_ directives.

filename sendemail email 'toaddress@email.com' ;

data _null_;

set somedataset;

put '!EM_TO! ' email_addr;

put '!EM_SUBJECT! ' subscription_name;

put name ' ,';

put 'This message was generated by a SAS data set';

put '!EM_SEND!';

run;

3Mar/090

SAS Proc Freq and crosstab basics

When thinking of the basic tools available in SAS, Proc Freq is on the list. This is one of those tools that can help you wrap your brain around your data. As an analyst, you should constantly be asking, what does my data look like. And this is where proc freq does the job.

So here is your data:

sashelp_flags

You want to know, what are the projects in this dataset and how many records are associated with each??

Proc Freq data=sashelp.flags;

table project;

run;

And here is your output:

flags_freq_output

Low and behold, it is the only project in the dataset with 220 records.

Lets take this very basic example one step further and say we want to crosstab this dataset. Pivot the dataset if you will. We want to see a distribution of descriptions by file. That code would look like this:

Proc Freq data=sashelp.flags;

table file*descript;

run;

And the output like this:

freq_crosstab_output

The order of the variables in the table statement determine how the cross-tab is setup. Try this code on your data. This is one of the most elementary ways to understand your datasets.