copyright © 2006, sas institute inc. all rights reserved. a sampler of what's new in base sas...
TRANSCRIPT
Copyright © 2006, SAS Institute Inc. All rights reserved.
A Sampler of What's New in Base SAS [email protected]
Copyright © 2006, SAS Institute Inc. All rights reserved.
Caramel, Nut, or Truffle?
DATA Step• User-Written Functions
• Data Set Lists
• Current Input Data Set Name
• INPUT with String Delimiter
PROC SQL• Un-PUT
• Faster DISTINCT
PROC SORT Linguistic Ordering
Encrypted Macro Storage
Copyright © 2006, SAS Institute Inc. All rights reserved.
Caramel, Nut, or Truffle?
DATA Step• User-Written Functions
• Data Set Lists
• Current Input Data Set Name
• INPUT with String Delimiter
PROC SQL• Un-PUT
• Faster DISTINCT
PROC SORT Linguistic Ordering
Encrypted Macro Storage
Copyright © 2006, SAS Institute Inc. All rights reserved.
Wrap in a Macro
%macro study_day(start, event, study_day);
n = &event - &start;
if n >= 0 then
&study_day = n + 1;
else
&study_day = n;
%mend;
Copyright © 2006, SAS Institute Inc. All rights reserved.
Bug in the Macro
data results;
set trial_data;
n = sum(of visits_jan--visits_dec);
%study_day(start, event, study_day)
if n > 5 then
...
Copyright © 2006, SAS Institute Inc. All rights reserved.
Bug in the Macro
data results;
set trial_data;
n = sum(of visits_jan--visits_dec);
n = event – start;
if n >= 0 then
study_day = n + 1;
else
study_day = n;
if n > 5 then
...
Copyright © 2006, SAS Institute Inc. All rights reserved.
Protected by a Function
data results;
set trial_data;
n = sum(of visits_jan--visits_dec);
study_day = study_day(start, event);
if n > 5 then
...
Copyright © 2006, SAS Institute Inc. All rights reserved.
Study Day Function
proc fcmp outlib=sasuser.funcs.trial;
function study_day(start, event);
n = event – start;
if n >= 0 then
return(n + 1);
else
return(n);
endsub;
Copyright © 2006, SAS Institute Inc. All rights reserved.
Copyright © 2006, SAS Institute Inc. All rights reserved.
Data Set Lists
#1 on 2006 SASware Ballot
Read Like-Named Data Sets
Syntax borrowed from DROP and KEEP
Copyright © 2006, SAS Institute Inc. All rights reserved.
Read a Bunch of Data Sets
data out;
set a1 a2 a3 a4 a5 a6 a7 a8 a9 a10
a11 a12 a13 a14 a15 a16 a17 a18
a19 a20 a21 a22 a23 a24 a25 a26
a27 a28 a29 a30 a31 a32 a33 a34
a35 a36 a37 a38 a39 a40 a41 a42
a43 a44 a45 a46 a47 a48 a49 a50;
run;
Copyright © 2006, SAS Institute Inc. All rights reserved.
Data Set Lists
data out;
set a1-a50(pw=pass123);
run;
data out;
set sales.jan:;
run;
Copyright © 2006, SAS Institute Inc. All rights reserved.
String Delimiter
"Top 10" SASware Ballot Item
Difficult to parse multi-character delimiters
INFILE DLMSTR=
Works like DLM=
Copyright © 2006, SAS Institute Inc. All rights reserved.
String Delimiter
data bad_guys;
length date time ip $ 16;
infile datalines dlm=' ' dsd;
input date time ip;
datalines;
"20APR2007" "12:56:46" "146.16.1.23"
run;
Copyright © 2006, SAS Institute Inc. All rights reserved.
String Delimiter
data bad_guys;
length date time ip $ 16;
infile datalines dlmstr=' ' dsd;
input date time ip;
datalines;
"20APR2007" "12:56:46" "146.16.1.23"
run;
Copyright © 2006, SAS Institute Inc. All rights reserved.
SET with INDSNAME=
"Top 10" SASware Ballot Item
Place current data set name into a variable
SET with INDSNAME = var
Copyright © 2006, SAS Institute Inc. All rights reserved.
SET with INDSNAME=
data results;
set gas_price_option
gas_rbid_option
coal_price_forward
coal_rbid_forward
indsname = cur_dataset;
...
run;
Copyright © 2006, SAS Institute Inc. All rights reserved.
DATA Step JavaObj
"Compute" methods written in Java
Call from DATA Step with JavaObj
Methods like Java Native Interface (JNI)
Uses dot syntax
Production in SAS 9.2
Experimental in SAS 9.1.3
Copyright © 2006, SAS Institute Inc. All rights reserved.
data results;
declare javaobj jo("myclass");
jo.callDoubleMethod("compute",
x, y, z, res);
...
DATA Step JavaObj
Copyright © 2006, SAS Institute Inc. All rights reserved.
DATA Step IN Operator
IN operator used simple array search
Now, IN searches a binary tree
9 12 14 17 19 23 50 54 67 72 76
Copyright © 2006, SAS Institute Inc. All rights reserved.
data _null_;
set customers;
if state in ('NC', 'SC', 'GA',
'TN', 'FL');
run;
DATA Step IN Operator
Copyright © 2006, SAS Institute Inc. All rights reserved.
Proc SQL Today
proc format;
value udfmt 1-3='small'
4-6='medium'
7-9='large';
proc sql;
select style as SmallStyles
from oracle.clothes
where put(size, udfmt.) = 'small';
Copyright © 2006, SAS Institute Inc. All rights reserved.
DBMS
Proc SQL Today
SAS® Session
select style as SmallStylesfrom oracle.clotheswhere put(size, udfmt.) = 'small';
SAS/Access Engine
select style,size from clothes
Copyright © 2006, SAS Institute Inc. All rights reserved.
DBMS
Proc SQL Today
SAS® Session
select style as SmallStylesfrom oracle.clotheswhere put(size, udfmt.) = 'small';
SAS/Access Engine
select style,size from clothes
Copyright © 2006, SAS Institute Inc. All rights reserved.
SAS® Session
select style as SmallStylesfrom oracle.clotheswhere put(size, udfmt.) = 'small';
DBMS
Proc SQL Tomorrow
SAS/Access Engine
select style as SmallStylesfrom oracle.clotheswhere (1 <= size and size <= 3);
Copyright © 2006, SAS Institute Inc. All rights reserved.
SAS® Session
select style as SmallStylesfrom oracle.clotheswhere put(size, udfmt.) = 'small';
DBMS
Proc SQL Tomorrow
SAS/Access Engine
select style as SmallStylesfrom oracle.clotheswhere (1 <= size and size <= 3);
Copyright © 2006, SAS Institute Inc. All rights reserved.
Proc SQL Today
proc sql;
select name
from oracle.employees
where put(bday, date5.) = '31OCT';
Copyright © 2006, SAS Institute Inc. All rights reserved.
Proc SQL Tomorrow
proc sql;
select name
from oracle.employees
where month(bday) = 10 and
day(bday) = 31;
Copyright © 2006, SAS Institute Inc. All rights reserved.
Proc SQL Today
proc format;
value nudfmt 0 = 'RED'
1 = 'NOTRED'
2 = 'GREEN'
other = 'BLACK';
proc sql;
select * from oracle.data where
put(color, nudfmt.) contains "RED";
Copyright © 2006, SAS Institute Inc. All rights reserved.
Proc SQL Tomorrow
proc format;
value nudfmt 0 = 'RED'
1 = 'NOTRED'
2 = 'GREEN'
other = 'BLACK';
proc sql;
select * from oracle.data where
color in (0,1);
Copyright © 2006, SAS Institute Inc. All rights reserved.
PROC SQL
Faster: SELECT DISTINCT
Faster: COUNT(DISTINCT var)
Hash Join Performance
Row Counts from DBMSes
Copyright © 2006, SAS Institute Inc. All rights reserved.
SELECT DISTINCT
proc sql;
create table distinct_values as
select distinct month, year
from customer_info;
quit;
Copyright © 2006, SAS Institute Inc. All rights reserved.
COUNT DISTINCT
proc sql;
create table count_distinct as
select count(distinct customerid)
from customer_info;
quit;
Copyright © 2006, SAS Institute Inc. All rights reserved.
Linguistic Sorting
Obs Binary Lowfirst Linguistic
1 Aaron aardvark aardvark
2 Aztec azimuth Aaron
3 Zeus Aaron azimuth
4 aardvark Aztec Aztec
5 azimuth zebra zebra
6 zebra Zeus Zeus
Copyright © 2006, SAS Institute Inc. All rights reserved.
Linguistic Sorting
proc sort data=names
out=sorted
sortseq=linguistic;
by name;
run;
Copyright © 2006, SAS Institute Inc. All rights reserved.
Numeric_Collation=ON
Obs Binary Linguistic
1 0123 Main St. Apt #12 123 Main St. Apt #1
2 123 Main St. Apt #1 123 Main St. Apt #2
3 123 Main St. Apt #103 0123 Main St. Apt #12
4 123 Main St. Apt #2 123 Main St. Apt #24
5 123 Main St. Apt #24 123 Main St. Apt #103
Copyright © 2006, SAS Institute Inc. All rights reserved.
Encrypted Macro Storage
%macro mymac(x, y) / store secure;
...
%mend;
Copyright © 2006, SAS Institute Inc. All rights reserved.
More Details
Search support.sas.com for:
Papers:
"User-Written DATA Step Functions"
"Creating Order out of Character Chaos"