creating a data driven length statement

data temp; set sasdata.&site._&year._&tmfrm.;
char_length=lengthn(name);
run;

proc means data=temp max noprint;
var char_length;
output out = means max(char_length) = max_length;
run;

%global max;

data test; set means;
call symputx("max",max_length);
put 'max =' max_length;
run;

data sasdata.&site._2007_04; set sasdata.&site._&year._&tmfrm.;
length newname $&max.;
newname=name;
run;

hour & timepart

I had an opportunity to use some functions that I had never used before, hour and timepart, when I needed to calculate the difference in time between two events. My diff_time variable was in seconds.

I first created an hour variable manually and using the hour function for data verification purposes before creating the time in hours and minutes variable:


************************************************;
* variables created for data verification ;
hours=(diff_time / 60) / 60;
hours_lapsed=hour(diff_time);
************************************************;
* convert length between closure and
* reopening to hours and minutes ;
time=timepart(diff_date);
format time time5.;

character function examples

********************************************************************;
* read in syslog files ;
* ------------------------------------------------------------------;
data mail (drop=id id2 id3 rectype spamscore) spam (keep=squid spamscore); infile r3 pad missover dlm=' ,';
length  mon $3.
day 3
time $8.
host $30.
rectype $6.
id $2.
id2 $2.
id3 $2.
squid $18. * SQuID = SendMail Queue ID # ;
to $40;    * Destination email address   ;
input mon day time host rectype @;
if rectype="sm-mta" then do;
* --------------------------------------------------;
* $char informat reads in entire string, including  ;
* blanks and punctuation.                           ;
* --------------------------------------------------;
input id id2 id3 squid @ 'to=' to $char50.;
* --------------------------------------------------;
* functions on squid effectively remove a trailing  ;
* colon (e.g. k3I400V6014162:)                      ;
* --------------------------------------------------;
squid=substr(squid,1,(indexc(squid,':')-1)) ;
* --------------------------------------------------;
* make 'to' lowercase, remove any blanks, and stop  ;
* reading the line when encountering a comma,       ;
* keeping only the first forwarding destination.    ;
* (e.g. to=First Last ,fl@user.edu) ;
* --------------------------------------------------;
to=lowcase(compress(scan(to,1,',')));
* --------------------------------------------------;
* extract email addresses that are enclosed in      ;
* brackets (e.g to=)              ;
* --------------------------------------------------;
if index(to,' 0 then
to=scan(substr(to,index(to,'');
* --------------------------------------------------;
* extract the information to the right of the colon ;
* e.g. to=        ;
* --------------------------------------------------;
if index(to,':') > 0 then
to=scan(substr(to,index(to,':')+1),1,'>');
output mail; /* legimate email */
end;
else if rectype="mimede" then do;
input @ 'MDLOG,' squid
@ 'spammish,' spamscore;
output spam;
end;
run;

crdte function

Creates a macro variable called create_dt that contains the value of a SAS dataset’s creation date:

libname library /path/to/sas/datasest/';
data _null_;
dsid = open('library.foo');
crdte = datepart(attrn(dsid,"crdte"));
rc = close(dsid);
call symputx("create_dt",put(crdte,mmddyy10.));

To use in a report title, use the following syntax:

title "As of &create_dt";