Document 7284217

Download Report

Transcript Document 7284217

MASUG
March 10, 2006
at FedEx
Agenda
• Announcements
• Tips & Tricks
• Lisa Horwitz from SAS
Announcements
• Next meeting May 2006
– Hopefully at the Doubletree on Sanderlin with
beverages and snacks (tentative 5-7 pm)
– SESUG speaker topic choice
• SAS training in Memphis
– SAS makes go/no go decision 3 weeks before
class date so register early!
– New location in FedEx Institute of Technology
Announcements (cont’d)
• Volunteers for Planning Committee?
– No experience needed and no compensation
provided 
• SUGI March 26-29
– Get together at the Kickback Party?
• SESUG October 8-9 in Atlanta
– Call for Papers closes April 7th
Complete Automation
of Routine Reports
Using Macro Variables
Memphis Area SAS Users Group
Friday, March 10, 2006
Michael Bates, Risk Analyst
First Horizon National Corporation
(901) 257-6038
[email protected]
Goal
• Submit a routine SAS job, in a open
session or in a scheduled queue, with no
user input needed
Why ?
• Eliminate user error
• Easily pass reports on to others
Determining Appropriate Time Frame
• Today’s Date
%let tdy = %sysfunc(today());
%put tdy = &tdy.;
• This Year
%let mnth = %sysfunc(month(&tdy.));
%put mnth = &mnth.;
• This Month
%let yr = %sysfunc(year(&tdy.));
%put yr = &yr.;
• This Week
%let wk = %sysfunc(week(&tdy.));
%put wk = &wk.;
• Last Month
%let l_mnth = %eval(&mnth. - 1);
%put l_mnth = &l_mnth.;
Log
1 %let tdy = %sysfunc(today());
2 %put tdy = &tdy.;
tdy = 16862
Log
3 %let mnth = %sysfunc(month(&tdy.));
4 %put mnth = &mnth.;
mnth = 3
Log
5
%let yr = %sysfunc(year(&tdy.));
6
%put yr = &yr.;
yr = 2006
Log
7
%let wk = %sysfunc(week(&tdy.));
8
%put wk = &wk.;
wk = 9
Log
9
%let l_mnth = %eval(&mnth. - 1);
10
%put l_mnth = &l_mnth.;
l_mnth = 2
Converting Into Date Format
• Date
%let d_date = %sysfunc(mdy(&mnth.,1,&yr.),date9.);
%put d_date = &d_date.;
– Log
11
%let d_date = %sysfunc(mdy(&mnth.,1,&yr.),date9.);
12
%put d_date = &d_date.;
d_date = 01MAR2006
• DateTime
%let dt_date = %sysfunc(mdy(&mnth.,1,&yr.),date9.):00:00:00;
%put dt_date = &dt_date.;
– Log
13
%let dt_date = %sysfunc(mdy(&mnth.,1,&yr.),date9.):00:00:00;
14
%put dt_date = &dt_date.;
dt_date = 01MAR2006:00:00:00
Running a job at a given time
•
Job can't run until 3rd of the month at 2:30pm
%let launch1 = %sysfunc(mdy(%sysfunc(month(%eval(&tdy.+30))),3,
%sysfunc(year(%eval(&tdy.+30)))),date9.):14:30:00;
%put launch1 = &launch1;
data _null_;
slept = wakeup("&launch1."dt);
run;
– Log
15
%let launch1 = %sysfunc(mdy(%sysfunc(month(%eval(&tdy.+30))),3,
16
%sysfunc(year(%eval(&tdy.+30)))),date9.):14:30:00;
17
%put launch1 = &launch1;
launch1 = 03APR2006:14:30:00
•
Job can't run until Sunday at 8:00am
%let launch2 = %sysfunc(mdy(
sysfunc(month(%eval(&tdy. + %eval(((%sysfunc(weekday(&tdy.))) - 8) * -1)))),
sysfunc(day(%eval(&tdy. + %eval(((%sysfunc(weekday(&tdy.))) - 8) * -1)))),
sysfunc(year(%eval(&tdy. + %eval(((%sysfunc(weekday(&tdy.))) - 8) * -1))))),
date9.):08:00:00;;
%put launch2 = &launch2;
data _null_;
slept = wakeup("&launch2."dt);
run;
– Log
18 %let launch2 = %sysfunc(mdy(
23
%sysfunc(month(%eval(&tdy. + %eval(((%sysfunc(weekday(&tdy.))) - 8) * -1)))),
24
%sysfunc(day(%eval(&tdy. + %eval(((%sysfunc(weekday(&tdy.))) - 8) * -1)))),
25
%sysfunc(year(%eval(&tdy. + %eval(((%sysfunc(weekday(&tdy.))) - 8) * -1))))),
26
date9.):08:00:00;
27
%put launch2 = &launch2;
launch2 = 12MAR2006:08:00:00
Customizing Output
• File Names
%let mon_yr_nm = %sysfunc(mdy(&mnth.,1,&yr.),monyy5.);
%put mon_yr_nm = &mon_yr_nm.;
– Log
28
%let mon_yr_nm = %sysfunc(mdy(&mnth.,1,&yr.),monyy5.);
29
%put mon_yr_nm = &mon_yr_nm.;
mon_yr_nm = MAR06
• DDE Column Or Row Selection
%let col = %eval((((&yr. - 2000) * 12) + &mnth.) - 74);
%put col = &col.;
– Log
30
%let col = %eval((((&yr. - 2000) * 12) + &mnth.) - 74);
31
%put col = &col.;
col = 1
• DDE Column Or Row Headings
%let col_name = %sysfunc(mdy(&mnth.,1,&yr.),monname9.);
%put col_name = &col_name.;
– Log
32
%let col_name = %sysfunc(mdy(&mnth.,1,&yr.),monname9.);
33
%put col_name = &col_name.;
col_name = March
Useful Date Functions
Returns the number of days between two dates
Returns the current date as a SAS date value
Converts a Julian date to a SAS date value
Extracts the date from a SAS datetime value
Returns the current date and time of day as a SAS datetime value
Returns the day of the month from a SAS date value
Returns a SAS datetime value from date, hour, minute, and second
Returns a SAS time value from hour, minute, and second values
Returns the hour from a SAS time or datetime value
Returns the integer count of the number of interval boundaries
between two dates, two times, or two datetime values
Increments a date, time, or datetime value by a given interval or
INTNX
intervals, and returns a date, time, or datetime value
JULDATE Returns the Julian date from a SAS date value
JULDATE7 Returns a seven-digit Julian date from a SAS date value
Returns a SAS date value from month, day, and year values
MDY
Returns the minute from a SAS time or datetime value
MINUTE
Returns the month from a SAS date value
MONTH
Converts the SAS date value to the date value of the specified
NLDATE
locale using the date-format modifiers
Converts the SAS datetime values to the time value of the specified
NLDATM
locale using the datetime format modifiers
Converts the SAS time or datetime value to the time value of the specified
NLTIME
locale using the time-format modifiers
Returns the quarter of the year from a SAS date value
QTR
Returns the second from a SAS time or datetime value
SECOND
Returns the current time of day
TIME
TIMEPART Extracts a time value from a SAS datetime value
Returns the current date as a SAS date value
TODAY
Returns the week number value
WEEK
WEEKDAY Returns the day of the week from a SAS date value
Returns the year from a SAS date value
YEAR
Returns the difference in years between two dates
YRDIF
Returns a SAS date value from the year and quarter
YYQ
DATDIF
DATE
DATEJUL
DATEPART
DATETIME
DAY
DHMS
HMS
HOUR
INTCK
Useful Date Formats
ddmmyy5.
ddmmyy6.
ddmmyy7.
ddmmyy8.
ddmmyy10.
date5.
date6.
date7.
date8.
date9.
ddmmyyc5.
ddmmyyd8.
ddmmyyp10.
ddmmyyn8.
mmddyy2.
mmddyy3.
mmddyy4.
mmddyy5.
mmddyy6.
mmddyy7.
mmddyy8.
mmddyy10.
mmddyyc5.
mmddyyd8.
mmddyyp10.
24/12
241205
241205
24/12/05
24/12/2005
16MAR
16MAR
16MAR03
16MAR03
16MAR2003
16:03
16-03-05
16.03.2005
16032005
10
10
1025
10/25
102505
102505
10/25/05
10/25/2005
10:22
10-22-05
10.22.2005
mmddyyn8.
mmyy5.
mmyy6.
mmyy.
mmyy7.
mmyy10.
mmyyc5.
mmyyd.
mmyyn4.
mmyyp8.
mmyys10.
monname1.
monname3.
monname5.
month.
monyy5.
monyy7.
year2.
year4.
yymmdd2.
yymmdd3.
yymmdd4.
yymmdd5.
yymmdd6.
yymmdd7.
yymmdd8.
10222005
10M05
10M05
10M2005
10M2005
10M2005
07:05
07-2005
0705
07.2005
07/2005
M
Mar
March
11
DEC05
DEC2005
05
2005
05
05
0504
05-04
050403
050403
05-04-03
yymmdd10.
yymmddc5.
yymmddd8.
yymmddp10.
yymmddn8.
yymmc5.
yymmd.
yymmn4.
yymmp8.
yymms10.
yymm5.
yymm6.
yymm.
yymm7.
yymm10.
yymon6.
yymon7.
yyq4.
yyq6.
yyq10.
yyqc4.
yyqd.
yyqn3.
yyqp6.
yyqs8.
2005-04-03
05:10
05-10-22
2005.10.22
20051022
05:07
2005-07
0507
2005.07
2005/07
05M10
05M10
2005M10
2005M10
2005M10
05JUN
2005JUN
05Q2
2005Q2
2005Q2
05:3
2005-3
053
2005.3
2005/3
Useful DateTime Formats
datetime.
datetime7.
dtdate.
dtdate9.
dtmonyy.
dtmonyy5.
dtmonyy6.
dtmonyy7.
dtwkdatx.
dtwkdatx3.
dtwkdatx8.
dtwkdatx25.
dtyear.
dtyear2.
dtyear3.
year4.
10NOV05:03:49:19
10NOV05
16APR00
16APR2000
OCT06
OCT06
OCT06
OCT2006
Monday, 16 October 2006
Mon
Mon
Monday, 16 Oct 2006
2006
06
06
2006
Lisa Horwitz
Systems Engineer Manager for
SAS