Peter Crawford Crawford Software Consultancy Limited 1 of 21
Learn hidden features in base SAS to impress colleagues Peter Crawford
So many features So much to learn So much being added to SAS languages So hard to keep up So, add some ideas from outside the box Some hidden nuggets (probably) not in courses Peter Crawford Crawford Software Consultancy Limited 3 of 21
6 GEMS (hidden nuggets in SAS languages) 1. _DATA_ - protect your interests (and others) 2. Use global characters in path on INFILE just in unix 3. /*.csv need not start a comment block 4. INFORMAT $ANYFDT what ANYDTxxx chooses 5. Macros hidden among SASAUTOS 6. Profile to review flow through data step Peter Crawford Crawford Software Consultancy Limited 4 of 21
Gem 1 _DATA_ - protects your interests DATA ; WORK.DATA1 WORK.DATA2 WORK.DATA3 OUT= _DATA_ ; DATAn convention %let sorted_input_data= &SYSLAST ; No worry of overwriting Peter Crawford Crawford Software Consultancy Limited 5 of 21
2 Global characters on INFILE unix d:\path\*.csv NOXCMD /*/*.csv Protect server INFILE &PATH/*.sas FILENAME= varname Peter Crawford Crawford Software Consultancy Limited 6 of 21
2.1 Global characters on INFILE unix Project1 Import Routines Code1 Logs data Cleanse Code2 Logs data Summarize Summary_code Logs data Derivation Excel models Test results Test code Analysis Analytic code Present Peter Crawford Crawford Software Consultancy Limited 7 of 21 Performance code /Pr*/*/*ode*/*.sas Only.sas files
3 /*.csv need not start a comment block D:\path\*.csv /*block comment*/? global character /*/*.csv /?*not a comment*/ 1 single character Relax, /?* won t be misinterpreted Peter Crawford Crawford Software Consultancy Limited 8 of 21
4 informat $ANYFDT what ANYDTxxx. chose Ad hoc PROC Import As you go any informat will do Informat ANYDTDTE. Agreed data structure Only agreed informats informat $ANYFDT. Explains what informat ANYDTxxx would choose on each row in each column Peter Crawford Crawford Software Consultancy Limited 9 of 21 9 of 23 Peter Crawford More Features to Impress
5 Macros hidden among SASAUTOS SAS Autocall library FILEREF sasautos DATA Step read input @'%macro ' macname ; Simple but! Simple but case-sensitive Peter Crawford Crawford Software Consultancy Limited 10 of 21
5.1 Macros hidden among SASAUTOS data all_provided_macros ; length filename filen $1000 macname $33 ; infile sasautos('*.sas') filename= filen dlm= ';(/% '; input @'%macro ' macname ; filename= filen ; run ; But this is case-sensitive Peter Crawford Crawford Software Consultancy Limited 11 of 21
5.2 Macros among SASAUTOS case-sensitive results Peter Crawford Crawford Software Consultancy Limited 12 of 21
5.3 Macros hidden among SASAUTOS input @'%macro ' macname ; input @ ; pos = find( _infile_, '%macro ', 'I' ) ; if pos ; input @(pos+6) macname ; Case sensitive Insensitive WHERE lowcase(macname) ne scan( filename, -2, './' ); Peter Crawford Crawford Software Consultancy Limited 13 of 21
5.4 Macros hidden among SASAUTOS WHERE lowcase(macname) ne scan( filename, -2, '.\/' ); Peter Crawford Crawford Software Consultancy Limited 14 of 21
5.5 Macros hidden among SASAUTOS NOTE: The data set WORK.PROVIDED_MACROS2 has 682 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.64 seconds cpu time 0.72 seconds 65 proc print n ; 66 WHERE lowcase(macname) ne scan( filename, -2, '.\/' ); 67 run ; NOTE: There Peter were Crawford 410 observations Crawford Software read Consultancy from Limited the data set WORK.PROVIDED_MACROS2 15 of 21 WHERE LOWCASE(macname) not = SCAN(filename, -2, '.\/'); NOTE: PROCEDURE
6. Profile a data step - Review data flow CPU time by statement big overhead Internal option many iterations to show to solve a big problem DSOPTIONS= profile It s a relative judgment Peter Crawford Crawford Software Consultancy Limited 16 of 21
6.1 Profile a data step statement counts and cpu Peter Crawford Crawford Software Consultancy Limited 17 of 21
6.2 Profile a data step step cpu statistics Peter Crawford Crawford Software Consultancy Limited 18 of 21
6.3 Profile a data step step cpu case sensitive Peter Crawford Crawford Software Consultancy Limited 19 of 21
6.4 Profile a data step statements case sensitive Peter Crawford Crawford Software Consultancy Limited 20 of 21
So many features Thank you for listening So much to learn So much being added I can to take SAS questions languages So hard to keep up So, add some ideas from If time outside permits the box Some hidden Peter.Crawford@blueyonder.co.uk nuggets (probably) not in courses Peter Crawford Crawford Software Consultancy Limited 21 of 21 21 of 23 Peter Crawford More Features to Impress
This layout is for full screen media only
Peter Crawford Crawford Software Consultancy Limited 25 of 21