the best of vansug tips and tricks · the best of vansug tips and tricks nate derby stakana...

20
The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1 / 20

Upload: others

Post on 22-Mar-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

The Best of VanSUG Tips and Tricks

Nate Derby

Stakana AnalyticsSeattle, WA

Vancouver SAS Users Group 5/11/16

Nate Derby Tips and Tricks 1 / 20

Page 2: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

The IN Operator with Integer Ranges

Colleen McGahan, 10/8/08

DATA sample;SET cohort;IF age in (10, 15:20, 25:30);

RUN;

Nate Derby Tips and Tricks 2 / 20

Page 3: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

Automatically Clearing the Log/Output Window

Nate Derby, 10/8/08

DM 'log' clear;DM 'odsresults' clear;

Nate Derby Tips and Tricks 3 / 20

Page 4: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

Changing . to Blank for Missing Numeric Variables

Cathy Rupp, 5/6/09

OPTIONS MISSING = '';

Nate Derby Tips and Tricks 4 / 20

Page 5: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

Dealing with Overlapping Ranges

Mei Chong, 10/7/09

PROC FORMAT;VALUE player (MULTILABEL)1 - 4 = "Class A"5 - 9 = "Class B"1 - 9 = "All Classes";

RUN;

PROC SUMMARY DATA=blah;FORMAT player player.;CLASS player / MLF;VAR score;

RUN;

Nate Derby Tips and Tricks 5 / 20

Page 6: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

The PVALUEX. Format

Ryan Woods, 5/5/10:

variable group_a group_b p_value

x 15.7 16.4 0.0000y 9.2 9.6 0.2517

variable group_a group_b p_value

x 15.7 16.4 <.0001y 9.2 9.6 0.2517

Nate Derby Tips and Tricks 6 / 20

Page 7: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

Email Report after Creating It in Batch Mode

Nadia Lesnikova, 11/17/10

%SYSEXEC COPY 'C:\MyFolder\MyReport.rtf''C:\Folder2\MyReport.rtf';

FILENAME sendmail EMAIL "[email protected]"SUBJECT="VanSUG 10-Year Progress Report";

DATA _NULL_;FILE sendmail;PUT 'Hi Colleen,';PUT 'Please review the updated progress report.'PUT 'It can be found in : C:\Folder2\MyReport.rtf';PUT 'Thanks!';

RUN;

Nate Derby Tips and Tricks 7 / 20

Page 8: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

Shortcuts with Arrays

Scott Albrechtsen, 5/4/11

DATA output;SET input;ARRAY vars a1 b2 c5 d2 g5 f3;DO i=1 to 6;vars(i) = vars(i) * 1.25;END;

DROP i;RUN;

DATA output;SET input;ARRAY vars a1 b2 c5 d2 g5 f3;DO OVER vars;vars = vars * 1.25;END;

RUN;

Nate Derby Tips and Tricks 8 / 20

Page 9: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

Quick Syntax Check

Ryan Knowles, 11/2/11

OPTIONS OBS=0 NOREPLACE;

Nate Derby Tips and Tricks 9 / 20

Page 10: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

Useful String Functions

Howard Cherniack, 5/30/12

CATX( sep, a, b, c, ... )

COMPL( str )

SCAN( str, n, delims )

SUBSTR( str, pons, len )

STRIP( str )

Nate Derby Tips and Tricks 10 / 20

Page 11: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

The WHICHN Function

Fareeza Khurshed, 5/30/12

IF x=a OR x=b OR x=c OR ...

WHICHN( x, a, b, c, ... )

Nate Derby Tips and Tricks 11 / 20

Page 12: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

Abbreviations for the Lazy and Forgetful

Núria Chapinal, 11/28/12:

Tools ⇒ Add Abbreviation

Nate Derby Tips and Tricks 12 / 20

Page 13: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

Exploring Data with Binary Variables

Dmitry Shopin, 5/28/14

DATA address;SET address;is_postal = NOT MISSING( postal_code );is_city = NOT MISSING( city );

RUN;

PROC FREQ;TABLES is_postal*is_city / LIST;

RUN;

Nate Derby Tips and Tricks 13 / 20

Page 14: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

Shortening Your DO Steps by IN: Arrays

Gillian Frosst, 11/26/14

ARRAY serialNum[25] serialNum1-serialNum25;DO a=1 to 25;IF SUBSTR( serialNum[a], 1, 2 ) = '12' THEN flag = 1;IF SUBSTR( serialNum[a], 1, 3 ) = '345' THEN flag=1;IF SUBSTR( serialNum[a], 1, 4 ) = '6789' THEN FLAG = 1;

END;

ARRAY serialNum[25] serialNum1-serialNum25;DO a=1 to 25;IF serialNum[a] IN: ( '12', '345', '6789') THEN FLAG = 1;

END;

Nate Derby Tips and Tricks 14 / 20

Page 15: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

Adding Native Excel Graphics to Excel Output

Jing Dong, 5/27/15

ODS EXCEL FILE="C:\temp.xlsx";TITLE "Sales by Region";

PROC MSCHART;DATA=work.summary CATEGORY=region WIDTH=4in POSITION="$D$1";WHERE region in( "Africa", "Asia", "Canada", "Pacific","United States" );

VCOLUMN sales;RUN;

ODS EXCEL close;

Nate Derby Tips and Tricks 15 / 20

Page 16: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

Adding Native Excel Graphics to Excel Output

Nate Derby Tips and Tricks 16 / 20

Page 17: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

NOUNIQUEKEY Option in PROC SORT

Eric Cai, 5/27/15PROC SORTDATA=sashelp.adomsgOUT=duplicatesUNIQUEOUT=singlesNOUNIQUEKEY;

BY msgid;RUN;

Nate Derby Tips and Tricks 17 / 20

Page 18: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

using ODS TRACE to Obtain Output

Jason Chen, 11/4/15

ODS TRACE ON;

PROC LOGISTIC DATA=testData;CLASS ais neuroloicalLevel / PARAM=ref;MODEL surgery=ais neurologicalLevel /LACKFIT RSQUARE;

RUN;

ODS TRACE OFF;

Nate Derby Tips and Tricks 18 / 20

Page 19: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

Three Useful SYSTEM Options

Guillaume Colley, 11/4/15

MERGENOBY=ERROR

COMPRESS=YES

NOREPLACE

Nate Derby Tips and Tricks 19 / 20

Page 20: The Best of VanSUG Tips and Tricks · The Best of VanSUG Tips and Tricks Nate Derby Stakana Analytics Seattle, WA Vancouver SAS Users Group 5/11/16 Nate Derby Tips and Tricks 1

Appendix

Check Them All Out!

VanSUG Website: vansug.ca

Nate Derby Tips and Tricks 20 / 20