Archive für Januar 2007

SAS: Contour Plot with PROC GCONTOUR

Contour PlotTo create interesting 3D Graphics which are easy to understand you can use PROC GCOUNTOUR.
With this procedure you are able to create graphics for your next presentation or for playful marketers.

 

The following Code and the picture are an example how to create Contour Plots:

data surface;
do i=1 to 50 by 1;
x=i;
do k=1 to 50 by 1;
x=x;
y=k;
z=round(sqrt(
5*y*(x**2)+3),1);
output;
end;
end;
run;

GOPTIONS xpixels=800 ypixels=600;
GOPTIONS CBACK=WHITE;

LEGEND1
LABEL=(FONT=‘Arial’ HEIGHT=8pt JUSTIFY=CENTER ‘Revenue:’ )
POSITION=(MIDDLE BOTTOM OUTSIDE)
across=4
down=1
value=(tick=1 height=5.5pt JUSTIFY=LEFT ‘Low’
tick=2 height=5.5pt JUSTIFY=LEFT ‘Low - Medium’
tick=3 height=5.5pt JUSTIFY=LEFT ‘Medium - High’
tick=4 height=5.5pt JUSTIFY=LEFT ‘High’)
CSHADOW=GRAY
CFRAME=CXE8E8E8
CBORDER=GRAY;

TITLE ‘Contour Plot’;
TITLE2 ‘PLOT: x * y * sqrt(5*y*(x**2)+3)’;

PROC GCONTOUR DATA = surface;
PLOT x * y = z /
PATTERN
LEGEND=LEGEND1
NLEVELS=4
SMOOTH
CFRAME=WHITE
CLEVELS=GREEN YELLOW ORANGE RED
;
RUN;
QUIT;
TITLE; TITLE2; FOOTNOTE;
     

SAS: Using GOTO Statement in Macro Steps

It is not perfect to use the GOTO statement in SAS Code. But if needed you can use the following macro structure:

%macro goto_struct(var);
%IF %QUOTE(&var) NE 16444 %THEN %DO;
%GOTO error; %
%error:
data error;
x=1;
output;
run;
%END;

%IF %QUOTE(&var) EQ 16444 %THEN %DO;
%GOTO ok; %
%ok:
data ok;
x=2;
output;
run;
%END;
%mend goto_struct;
%goto_struct(
100);
 

Using email functions with SAS

SAS provides several possibilities to send out emails. This is a good feature to get statusinformation while a SAS-program is running.

1st - sending emails with SAS/Macro (Author: DeVenezia.com):

%macro quikmail (to,subj,body);
%if (%superq(to) eq ) %then %let to=foobar;
%if (%superq(to) ne and %superq(subj) ne and %superq(body) ne) %then %do;
filename quikmail email “%superq(to)” subject=“%superq(subj)”;
data _null_;
file quikmail;
put
“%superq(subj)”;
%let body=%left(%superq(body));
%do %until (%superq(body) eq);
%let p=%index(%superq(body),\n);
%if (&p eq 0) %then %do;
put
“%superq(body)”;
%let body=;
%end;
%else %do;
put
“%substr(%superq(body),1,%eval(&p-1))”;
%if (%eval(&p+2) gt %length(%superq(body))) %then
%let body = ;
%else
%let body = %substr (%superq(body),%eval(&p+2));
%end;
%end;
run;
%end;
%mend quikmail;
%quikmail(MyEmail@provider.com, Subject , MyText);

2nd - sending emails with Datastep:

data _null_;
filename mail email
to = (MyEmailAdress)
subject =
“SAS Mailtest”
/*attach = (”Path and Filename 1,Path and Filename 2″)*/;
file mail;
put “Zeile 1″;
put “Zeile 2″;
run;

SAS: Geomapping Process (Maps based on ZIP Code)

DeutschlandkarteThe following PDF Document contains a process description to create maps with SAS. It is a Step by Step Documentation including SAS Code and SAS Macro.
read PDF (14KB):
SAS Geomapping Process

SAS: Import and Export Data

If you want to import data into SAS with SAS Code you can use the following structure:

data my_table;
infile “[Type in the full Path where to find the data]”
delimiter=‘,’
missover
dsd
lrecl
=32767
firstobs=2
;
length
first_field $ 24
;
input
first_field $
;
label
first_field = “first_field”
;
run;

If you want to export data you can use the following structure. If you need more detailed code you can use the procedure output in the LOG window.

proc export data=my_table
outfile=“[Type in the full Path where to find the data]”
dbms=dlm;
delimiter=‘|’;
run;    

Key Functions in Oracle SQL

Oracle Snapshot

Here you find a really good link to a documentation for the key functions in Oracle SQL (e.g. “to_char”). The description contains the most important date, number and string functions.
Check out: Harvard Documentation

SAS: SQL Pass Through

With this SAS Program you are able to connect to a database with SQL Pass Through via ODBC. The advantage is, that the SQL Statement will be processed by the resources of the database. The disadvantage is, that you cannot use SAS specific functions which are not supported by the database sql language.

proc sql;
connect to odbc (dsn=”…” user=”…” password=”*****”);
create table my_table as
select * from connection to odbc
(
select

from

where

);
disconnect from odbc;
quit;

Geomapping with SAS

Karte

Here you can find my presentation for the SAS Forum. I received excellent Feedback and got in touch with other SAS Experts. We improved the SAS Maps so that we are able to show cities on the map.
Download (~3MB):
AOL Geomapping

Lets talk about Analysis

I think it would be great to share my knowledge in the field of Business Intelligence, SAS Programming and Campaign Management with other great experts. Therefore I created this Weblog to post my ideas.

|