MASUG - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

MASUG

Description:

June 9-11 in Little Rock, AR. Presentations June 10 ... St. Jude Children's Research. R. E. T. A. S. T. C. 4x4 Scatter Matrix: Definition. Scatter4 Macro ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 34
Provided by: Stephanie258
Category:
Tags: masug | jude | plot | polly | presenters

less

Transcript and Presenter's Notes

Title: MASUG


1
MASUG
  • May 19, 2005

2
Id like to say
  • Thank You! to SAS for sponsoring the food this
    evening.

3
We have a new web URL!!! MASUGTN.org
4
SCSUG Training Day
  • June 9-11 in Little Rock, AR
  • Presentations June 10
  • Workshops June 9 11
  • Presenters from SAS, SESUG, MASUG
  • Postcards on registration table
  • Links posted on masugtn.org
  • or see SCSUG.com

5
SESUG Conference
  • October 23-25 in Portsmouth, VA
  • See link on our page
  • or go to SESUG.org

6
SUGI 31
  • March 26-29 in San Francisco

7
Brief Announcement
  • From Polly Mitchell-Guthrie
  • Director, Americas Education Programs SAS

8
Tips Tricks
9
SAS Code
  • scatter3.sas and scatter4.sas will be posted on
    our web site after the meeting for your reference.

10
PLOT MATRICES
  • Prepared by
  • Mehmet Kocak
  • St. Jude Childrens Research

11
4x4 Scatter Matrix Definition
12
Scatter4 Macro
  • macro scatter4(data, var1, var2, var3, var4,
    templib, templat, gnamegseg, ftitleScatter Plot
    Matrix)

13
Sample Data
  • data sampledata
  • do i1 to 100
  • iq20rand('normal')2
  • ageiqrand('normal')
  • weightage10rand('normal')5
  • heightweightrand('exponential')5
  • output end run

14
Macro Program Execution
  • include "c\mehmet_kocak\macros\scatter4.sas"
  • scatter4(sampledata, iq, age, weight, height,
  • mytemp.temps, scat4, gnamemyfolder,
  • ftitleMy Scatter Plot Matrix)

15
Final Product
16
3x3 Scatter Plot Matrix
  • Scatter3.sas macro does the same thing for three
    variables of interest
  • Template that produces a 10 panel plot (3x31 for
    title) is scat3.
  • If you like to use GSEG as your graphics output
    path, make sure that there is no graph in it
    before you run the macros.
  • Thanks.

17
SAS Code
  • scatter3.sas and scatter4.sas will be posted on
    the web site for reference.

18
More Tips Tricks
  • This is a macro that will receive a SAS Dataset
    name as a Parameter, and will build two GLOBAL
    variables (nbr_cols and nbr_obs). These are then
    available for use anywhere within that SAS
    session. It also writes out to the log a message
    helpful for debugging a SAS program.

19
  • MACRO NUMOBS( DSN )
  • GLOBAL nbr_cols nbr_obs data _null_
  • set dsn (obs1) NOBSobscnt
  • array aa _character_
  • array nn _numeric_
  • vars dim(aa) dim(nn)
  • call symput('nbr_cols',vars)
  • call symput('nbr_obs',obscnt)
  • stop
  • run
  • (continued)

20
  • let my_msg str( TRIM( Nbr_Obs) X TRIM(
    Nnbr_Cols) Observations for DSN ) let len
    LENGTH( my_msg )
  • let border
  • DO i 1 TO LEN
  • let borderborder
  • end put border
  • put my_msg NOW
  • put border
  • options mprint mlogic nonotes
  • run
  • MEND NUMOBS
  • To use NUMOBS( my_sas_Dsn) It produces in the
    log
    44 X 11 Observations for my_sas_Dsn

21
The Power ofMacro Lists
22
Macro Lists
  • A simple but powerful programming concept is a
    data list
  • A simple implementation of this in the SAS macro
    language is a single macro variable that contains
    the list
  • Each list element is delimited from another by a
    separator usually a simple blank

23
What kind of things are useful as a macro list?
  • Variable names
  • Dataset names
  • Data from datasets
  • Dates
  • Control values
  • Devices, printers, files, etc

24
An example variable names
  • let bylist acode bcode ccode
  • let metrix x1 x2 x3 x4
  • proc sort datamyData
  • by bylist t
  • proc summary nway
  • var metrix
  • class bylist t
  • output outmySums sum
  • proc print
  • var t metrix
  • by bylist
  • run

25
Now comes the power part
  • Frequently, multiple version of the same list
    would be very useful.
  • let metrix x1 x2 x3 x4
  • let totals t_x1 t_x2 t_x3 t_x4
  • let pcts p_x1 p_x2 p_x3 p_x4
  • data stats
  • merge tbl1 tbl2
  • by bylist t
  • array metrx metrix
  • array totals totals
  • array pcts pcts
  • do over metrx
  • pcts metrx / totals
  • end
  • run

26
Wheres the power?
  • Using macro lists makes code
  • More readable
  • Easier to write
  • Easier to understand
  • Easier to maintain
  • But wait, theres more
  • Fewer typo errors write the list once
  • Makes you more productive faster coding and
    less debugging
  • Last (but especially important to the power
    issue) lists can be manipulated!!

27
Prefixing elements in a listLiPrefix
  • In the last example we typed each list (more
    opportunity for error)
  • Using a macro function, we type the list once,
    then simply build each derivative list
  • let metrix x1 x2 x3 x4
  • let totals LiPrefix(metrix,t_)
  • let pcts LiPrefix(metrix,p_)

28
Adding a suffixLiSuffix
  • Occasionally we want to use a suffix instead
  • let metrix adv yld wpp dpp
  • do i1 to 9
  • let varlist LiSuffix(metrix,i)
  • data mydatai
  • set mydatai
  • keep bylist varlist
  • run
  • end

29
Id like to rename a list of variables.How do I
do that?!
  • Difficult with only LiPreffix and LiSuffix
  • Simple with RenameList
  • let metrix pkgs nrev brev disc wgt
  • let totals LiPrefix(metrix,t_)
  • data myData
  • merge myData
  • myTotals(rename(RenameList(metrix,tota
    ls)))
  • by bylist
  • run
  • RenameList builds the syntax especially for the
    rename clause

30
A Suite of Macro List Tools
  • LiPrefix, LiSuffix, RenameList
  • ListOp list operations (union, intersection,
    subtraction)
  • Lindex returns index number of a list element
  • Linsert insert an element
  • ListContains boolean, does the list contain the
    specified element?
  • QList quotes each element of a list
  • CommaList insert commas between elements of a
    list (for SQL lists)
  • WordCnt returns number of elements
  • SubList like substr but for lists
  • RevList reverse the order of a list
  • PutList formats each element using a SAS format
  • LastWord returns the last element of a list
  • MakArray transform a list into an array
  • Email me to request a zip file wjsmith1_at_fedex.com

31
LiPrefix
  • /
  • Name liprefix (List Item Prefix)
  • Desc Returns a list with the specified
    prefix prefixed to each item.
  • Type Macro Function - List
  • Usage liprefix ( list , prefix )
  • Where list is a space delimited list
  • prefix is any string of characters
  • Examples
  • 1) let fylist1996 1997 1998
  • let newlistliprefix(fylist,str(
    FY))
  • put gt newlistnewlist
  • gt newlistFY1996 FY1997 FY1998
  • 2) let datelist01JAN1999 01FEB1999
    01MAR1999
  • let newlistliprefix(datelist,bquote(
    '))
  • let newlistlisuffix(bquote(newlist),
    bquote('d))
  • put gt newlistnewlist
  • gt newlist'01JAN1999'd '01FEB1999'd
    '01MAR1999'd
  • History
  • 3/15/00 Walt Smith - development

32
LiSuffix
  • /
  • Name lisuffix (List Item Suffix)
  • Desc Returns a list with the specified
    suffix appended to each item.
  • Type Macro Function - List
  • Usage lisuffix ( list , suffix )
  • Where list is a space delimited list
  • suffix is any string of characters
  • Examples
  • 1) let fylist1996 1997 1998
  • let newlistlisuffix(fylist,str(,))
  • put gt newlistnewlist
  • gt newlist1996,1997,1998,
  • 2) let datelist01JAN1999 01FEB1999
    01MAR1999
  • let newlistliprefix(datelist,bquote(
    '))
  • let newlistlisuffix(bquote(newlist),
    bquote('d))
  • put gt newlistnewlist
  • gt '01JAN1999'd '01FEB1999'd
    '01MAR1999'd
  • History
  • 3/15/00 Walt Smith - development

33
Q A
  • with Chris Ricciardi
  • Systems Engineer with SAS
Write a Comment
User Comments (0)
About PowerShow.com