Proc SQL and the power of select into
I have referenced this paper many times. Great help in using the power of proc sql with macro variables. Great for building lists of values and dynamic code.
http://www.nesug.org/Proceedings/nesug97/coders/eddlesto.pdf
Syntax:
SELECT
object-item <,objectitem>...
<\ INTO macro-variablespecification <, macro-variablespecification> ...>
FROM from-list ...;
Hello from SAS Global Forum 2013!
SAS Global Forum 2013 is underway. So far we have focused on Visual Analytics and High Performance Analytics Server. All great advances in SAS computing power.
This conference is set to be a good one. If you weren't fortunate enough to make it to San Francisco this year, watch live via SAS stream.
http://support.sas.com/events/sasglobalforum/2013/live.html
SAS Administration – Creating a client only software depot
If you need to get Enterprise Guide out to your users and you don't want them to have access to the rest of the SAS software, create a software depot on a network location that only has the clients included.
In order to do this you will need to do the following steps.
Navigate to your SAS Deployment Manager folder. Find the setup.exe (windows, .sh for linux, etc..).
setup.exe -subsetclients
By using this command line option, the normal 'by Foundation product' will become 'by product'. This will allow you to pick the clients you want included in the new depot.
Also note that there is a -subsetnonconfig option as well. This allows you to include foundation products and clients in a new depot.
See page 20 of this support doc for more details (SAS Support Doc).
Exporting without double quotes
One of our junior programmers shot this one over after fighting with Proc Export for some time to remove the quotes from a string.
His need: export a single column of data without headers or quotes.
How he did it, quick and easy.
data _null_;
set inputdateset;
file "outputfilename";
put outputcolumnname;
run;
Sometimes the simple solutions are right in front of us.
Accessing files via SFTP in SAS
Secure File Transfer Protocol has become the standard for transferring files outside our organization. However, it is not always the easiest thing to do in SAS. Here are a few code examples for you to steal.
Importing a CSV file over SFTP:
%let host=afhood.com;
%let sftpOption=-o IdentityFile=/home/user/.ssh/id_rsa;
%let filename=theFile.csv;
%let sftpPath=/home/remoteuser/dir/;
filename myfile sftp "&sftpPath.&filename." host="&host." options="&sftpOption.";
proc import datafile= myfile
out=sftp_file
dbms=dlm
replace;
delimiter= ",";
getnames=yes;
run;
If you have any SFTP related questions, or need help building your automated file retrieval, let us know.
Hadoop and SAS?
I recently read short blog post from Mike Ames @ SAS about the possibility of development within SAS to leverage Hadoop.
I can tell you that a number of digital marketing projects we've worked on in the last couple of years have all tackled their version of big, real-time data problems. Hadoop is one of many ways to overcome this hurdle.
SAS has its role to play in the digital marketing world as well. No one is better at batch processing to create personal customer experiences.
However, we get creative with database and custom software to make the two work together. We look forward to SAS pushing into big data and real-time in a big way. Stored proc's in SAS are a good start, but just that.
Here is the blog post mentioned above - http://blogs.sas.com/content/datamanagement/2011/08/29/sas-hadoop-and-big-data/
SAS Altlog option
If you run a production SAS environment or even a development environment for that matter, it is nice to have a specific location for all logs to be written and managed. ALTLOG helps achieve this.
The ALTLOG option can be set numerous ways, but we typically utilize 2.
1. As an option on the command line. Example:
sas sasprogram -altlog /my/log/dir/sasprogram_$timstamp\.log
2. Globally in the sas configuration file. This is wonderful as an administrator. All of the logs drop into one location for easy cleanup or archival. Users can specify an alternate location if they don't want it in the default, so everyone wins.
Making SOAP calls from SAS! Integrating with web services
One of the issues with SAS for many IT departments is the lack of integration with service oriented architecture (SOA). The good news is with many new features coming online with versions 9.X+ are service oriented.
Lets look quickly at the Proc SOAP procedure now available.
For those SAS programmers out there that aren't familiar with SOAP or services, get your basis here: SOAPUser-Basics
In a nutshell, SOAP is transporting XML data via a HTTP Post. In order to make a successful SOAP call from SAS you need a couple of things.
1. a request XML file
2. a repsonse XML file
3. a webservice URL and WSDL (Web Service Definition Language) -Think webservice users manual
Here is a simple example of a SOAP call we use on a daily job.
filename rqst_xml 'some file system reference';
* Create the XML;
data _null_;
set input_dataset;
file rqst_xml;
if first.records=1 then do;
put '<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Header>
<requestingSystem>SAS</requestingSystem><requestingFunction>DemoSasScript</requestingFunction>
</soap:Header><soap:Body>
<requestedData>';end;
datasetData;
if last.records=1 then do;
put '</requestedData>
</soap:Body></soap:Envelope>';
end;
run;
filename rspns_xml 'some file system reference';
%let URL=http://webservice_url/service;
proc soap in=rqst_xml
out=rspns_xml
url=&url;
run;
Upon executing the call, you can read in the rspns_xml data with the SAS XML engine.
This is meant to be a simple example with very limited scope. Service architecture can quickly get complicated with error and condition handling. Please let us know if you need help with your SAS architecture or coding.
SQL tip – Inner join shorthand with USING
We write a LOT of SQL here and although SQL is a powerful database language, it can be tedious. So here is one tip for shortening all that typing.
Typical join sytax:
select some_columns
from one_table join another_table on one_table.column_1 = another_table.column_1 and one_table.column_2=another_table.column_2
where some_column > someother_column ;
Not too bad, right?
In order for this tip to work, you must be joining on columns with the same name (ie. column_1 and column_2 have the same name in both tables).
Here it is:
select some_columns
from one_table join another_table using (column_1, column_2)
where some_column > someother_column ;
Now, in our example it's not a drastic difference in coding, but as any programmer knows, this shorthand example doesn't accurately represent the real world. So give this syntax a try on your next project and let us know if it doesn't save you some typing.
CRM technologies
As we begin to add posts in 2011, we stepped back to look at our business and our blog. We realized that the two are perfectly aligned. Although the majority of our focus is within the SAS product suite, our focus is marketing analytics and operations.
Given that, it is time for us to expand our commentary. So, in the coming weeks you will begin to see more content regarding some of our other technology partners including Teradata, Netezza and Unica.
If you have a question about a particular technology or topic, we'd love to hear from you. Comment below or email us a hello@afhood.com .