INCLUDE_DATA

Category Archives: Programming

Dramatically Increasing SAS DI Studio performance of SCD Type-2 Loader Transforms

In SAS DI Studio 3.4 (and I imagine in future versions), the prepackaged code for the SCD Type-2 Loader works like this: Does the dataset exist? If not, create an empty dataset with structure and indexes as defined from metadata. Then detect differences between it and the source dataset and the target dataset, expire any [...]

Easy Inserting/Appending Libraries into FMTSEARCH path lists in SAS 9.2

In SAS 9.1.3 and prior, Options list (such as FMTSEARCH for libraries with format catalogs, and SASAUTOS for paths that contain macros shared across jobs) were annoying to work with. If you have nested code that wants to add a library or a path the list, doing so like this could potentially clobber statements executed [...]

Counting distinct variables in SQL with SAS

One way to get the count of distinct variables, which works in most flavors of SQL, is to use a subquery. For instance, in Oracle this is:
SELECT count(SELECT DISTINCT foo FROM table) FROM dual
In SAS, using PROC SQL, you can do that too, but you can also simply do this:
SELECT count(distinct foo) FROM table

For loops in SAS

When coding for loops in SAS, one neat thing to remember is that all of the parts of it are optional.
start <TO stop> <BY increment> <WHILE(expression) | UNTIL(expression)>
http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000201276.htm
So in another language, what might be
for(int i=0;i < max;i++) {
In SAS, you can leave out the “by 1″, since it’s the default increment. So this would be
do [...]

Removing formats from all variables in a SAS Dataset

In SAS, every field/variable in a table/dataset can be given a format. This format tells SAS how to display the data. The following datastep will create a table called “formatted” having 1 row containing 3 variables: x, y, and d.
data formatted;
x=9000;
y=42;
now=16761;
format x comma6.;
format y dollar5.;
[...]

Sending HTTP Requests without Reloading and without AJAX

Supposing I have a simple HTML form that looks like this:
<form method=”post” action=”/SomeServlet”>
<input type=”text” name=”message” value=”Hello Server” />
<input type=”submit” value=”Send” />
</form>
And supposing I have a Servlet mapped at the path /SomeServlet, consisting of the code:
public class SomeServlet extends HttpServlet {
protected void doPost(HttpServletRequest request,
[...]

Converting between Date and Datetime in SAS

In SAS, fields are either character of varying length, or numeric. No exceptions. Temporal values such as Date and Date/Time are stored as either the number of days or seconds since 1960 January 1st.
In order to convert from Date/Time to Date, and from Date to Date/Time, you could divide or multiply respectively by 86400 (the [...]

Static Java List Instantiation

But it recently occurred to me that with variable-length methods, I can simply call asList like this:

List<String> strings = Arrays.asList(foo","bar");

Barcamp 2009 Registration is open!

Raleigh BarCamp registration is open. Register here, and do so soon to stake your seat! I couldn’t make it to last year’s, but look forward to this year’s.
A BarCamp is an unconference where people interested in a wide range of technologies come together to teach and learn. … Rather than having scheduled speakers, everyone pitches [...]

Reverse the Bits in a Byte in 3 operations

This is among many brilliant hacks from this page.
b = (b * 0×0202020202ULL & 0×010884422010ULL) % 1023;
The multiply operation creates five separate copies of the 8-bit byte pattern to fan-out into a 64-bit value. The AND operation selects the bits that are in the correct (reversed) positions, relative to each 10-bit groups of bits. The [...]