Tuesday, January 19th, 2010
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 [...]
Tuesday, October 27th, 2009
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 [...]
Monday, October 26th, 2009
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
Wednesday, October 7th, 2009
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 [...]
Wednesday, August 12th, 2009
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.;
[...]
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 [...]
Friday, January 23rd, 2009
It works. Just follow the instructions.
Tuesday, September 16th, 2008
If your SQL code has a nested select that references a column in an outer select, such as the following, it may be possible to rewrite to perform orders of magnitude faster.
proc sql;
create table new_rates as
select
from work.exchange_rate n
where not [...]
So my coworker was having a problem where he was reading a dataset that he did not own. It was a SAS9 dataset encoded in UTF-8, and contained ™ (U+2122), the trade mark sign. His SAS session was running a local encoding of latin1, ISO_8859-1, which did not have it.
My instinct says, it should convert [...]