Transcript slides
Systematically Reordering Axis in SAS Graph Brian Shen Web: www.ppdi.com A leading global CRO Introduction SAS default ordering for Major axis tick values is sometimes not desirable for procedures like GPLOT, GCHART, etc., as examples provided. Reordering the major axis values often takes significant amount of time for programmers, especially for generating big number of graphs for different parameters, or for data changing on daily basis, like marketing data. A leading global CRO SAS Default: Too Many (18) Tick Numbers 0 -10000 -20000 -30000 -40000 -50000 -60000 -70000 -80000 -90000 -100000 -110000 -120000 -130000 -140000 -150000 -160000 -170000 GPLOT : MIN = - 168000 MAX = - 2 DEFAULT -SAS A leading global CRO SAS Default: Font Size Change causes order changed 0 -20000 -40000 -60000 GPLOT: -80000 MIN = - 168000 -100000 MAX = - 2 -120000 -140000 -160000 -180000 DEFAULT-SAS A leading global CRO SAS Default: Tick values look strange 2.74E-07 2.24E-07 1.74E-07 1.24E-07 GPLOT: 7.40E-08 MIN = -1.36E-7 2.40E-08 MAX = 2.68E-7 -2.60E-08 -7.60E-08 -1.26E-07 -1.76E-07 DEFAULT-SAS A leading global CRO SAS Default: Only non-negative order was generated for Data with negative values 30000 20000 GPLOT: MIN = -0.002 MAX = 20000 10000 0 DEFAULT-SAS A leading global CRO SAS Default: Plot shrinks into a line if “label =none” AXIS option is specified GPLOT: MIN = 777 MAX = 777 777 DEFAULT-SAS A leading global CRO SAS Default: No plot generated for missing data WARNING: ALL VALUES MISSING or out of range for ( y * x ). Check to see if VAXIS= or HAXIS= list is incorrect. A leading global CRO MATHEMATICAL LOGICS TO RECALCULATE AXIS ORDERING To resolve the issues mentioned above, new mathematical logics are presented to calculate axis order, using SAS macro languages (%ORDER). Seven major steps are included for the new ordering mechanisms. For more details, please refer to the macro. A leading global CRO STEP 1: Get the data RANGE either from the dataset variable or by user defined MIN or MAX. For Example: Min = - 301, Max = 401 Range = 702; Min = -0.001, Max = 0.0001 Range = 0.0011; Special case for range equal to 0: If Min = Max = 0, reset Min = - 0.5, Max = 0.5; If Min = Max and not equal to 0, extend Min/Max to half of their absolute value on both direction. For example, if Min=Max=50, Reset Min = 25, Max =75. A leading global CRO STEP 2: Divide range by 10 to get interim result, called RESULT1, if RESULT1 > 1, round it to single digit. For Example: 702/10 = 70.2 RESULT1 = 70; 0.0011/10 = 0.00011 RESULT1 = 0.00011; A leading global CRO STEP 3: Divide RESULT1 by a DIVIDER to make the new result, called RESULT2, in a range between 0 to 10, and DIVIDER [10n, n=must be integers], which must be exponents with base 10, like …, 0.01, 0.1, 1, 10, 100, …, etc. For Example: 70 / 10 = 7 RESULT2 = 7, 0.00011 / 0.0001 = 1.1 RESULT2 = 1.1, DIVIDER = 10; DIVIDER = 0.0001; A leading global CRO STEP 4: Get the initial step, called STEP1, based on the following logics: If . < RESULT2 < =2.5, STEP1 = 2.5; If 2.5 < RESULT2 < =6.2, STEP1 = 5; If 6.2 < RESULT2 < 10, STEP1 = 10; For Example: RESULT2 = 7 STEP1 = 10 RESULT2 = 1.1 STEP1 = 2.5 A leading global CRO STEP 5: Get the STEP for axis order by multiplying STEP1 by DIVIDER by 2, i.e., STEP = STEP1*DIVIDER*2. : For Example: Step1 =10, divider= 10 STEP = 10 * 10 * 2 = 200; Step1 =2.5, divider= 0.0001 STEP = 2.5 * 0.0001 * 2 = 0.0005 A leading global CRO STEP 6: Get the LOW and HIGH value for ORDER using the following formula: LOW = Floor(MIN/STEP)*STEP HIGH = Ceil(MAX/STEP)*STEP ORDER = LOW to HIGH by STEP For Example: Min = - 301, Max = 401 ORDER= -400 TO 600 by 200 Min = 0.001, Max = 0.0001 ORDER = -0.0010 to 0.0005 by 0.0005 A leading global CRO STEP 7: If both Min and Max are nonnegative or non-positive, the LOW and HIGH must both be non-negative or nonpositive [Except for Min = Max = 0]. If Min and Max are in different signs, LOW and HIGH must also be in different signs. A leading global CRO Sample Calls %order( Dsn = sashelp.cars, var = mpg_city, max = 50.7 , order_name = y_order, valuelist_name = y_tickvaluelist) This call will use Min of MPG_CITY from dataset SASHELP.CARS and max = 50.7 to calculate axis order. %order( var max = -0.7, = 50.7); This call will use Min of -0.7 and max = 50.7 to calculate axis order. A leading global CRO Macro Variables Generated for AXIS ordering This is for GPLOT/GCHART/SGPLOT, etc. Y_ORDER: =10 to 60 by 10 Those three are designed for GTL Y_TICKVALUELIST: 10 20 30 40 50 60 VIEWMIN: 10 VIEWMAX: 60 A leading global CRO Apply results for your graph programming: For GPLOT, etc: AXIS1 Label = none order = (&y_order.) offset=(0, 3)pct; For GTL: yaxisopts=( linearopts =(viewmin = &viewmin viewmax=&viewmax tickvaluelist= (&y_tickvaluelist.))); A leading global CRO Compared Result with SAS Default Min | Max GPLOT DEFAULT (Tick Numbers) GTL DEFAULT (Tick Numbers) WARNING: Y=Y is invalid. The option expects at least one non-missing value in the column. Graph is Generated with empty AXIS %ORDER (Tick Numbers) WARNING: ALL VALUES MISSING or out of range. Graph will be Generated with AXIS = 999 to 9999 by 9000. Can make revision to be consistent with GTL Missing | Missing WARNING: ALL VALUES MISSING or out of range. No plot will be Generated 0|0 0 to 0 by 0 (1) plot shrinks into a line Label = none is specified in AXIS statement 0 to 0 by 0 (1) -1 to 1 by 0.5 (5) 1|4 1 to 4 by 1 (4) 1 to 4 by 0.5 (7) 1 to 4 by 1 (4) 1.1 | 6 1 to 6 by 1 (6) 1 to 6 by 1 (6) 1 to 6 by 1 (6) 100 | 635 100 to 700 by 100 (7) 100 to 700 by 100 (7) 100 to 700 by 100 (7) 777 | 777 777 to 777 by 0 (1), 777 to 777 by 0 (1) 200 to 1200 by 200 (6) -0.002 | 20000 0 to 30000 by 10000 (4) 0 to 20000 by 5000 (5) -5000 to 20000 by 5000 (6) -1.36E-7 | 2.68E-7 -1.76E-7 to 2.74E-7 by 0.5E-7 (10) -2E-7 to 3E-7 by 1E-7 (6) -2E-7 to 3E-7 by 1E-7 (6) -168000 | -2 -170000 to 0 by 10000 (18) -200000 to 0 by 50000 (5) -200000 to 0 by 50000 (5) A leading global CRO Compared Result with SAS Default 0 -10000 -20000 -30000 -40000 -50000 -60000 -70000 -80000 -90000 -100000 -110000 -120000 -130000 -140000 -150000 -160000 -170000 0 -50000 GPLOT: MIN = - 168000 -100000 MAX = - 2 -150000 -200000 DEFAULT-SAS REDEFINED A leading global CRO Compared Result with SAS Default 2.74E-07 3.00E-07 2.24E-07 2.00E-07 1.74E-07 1.24E-07 GPLOT: 1.00E-07 7.40E-08 MIN = -1.36E-7 2.40E-08 MAX = 2.68E-7 0.00E+00 -2.60E-08 -7.60E-08 -1.00E-07 -1.26E-07 -1.76E-07 -2.00E-07 DEFAULT-SAS REDEFINED A leading global CRO Compared Result with SAS Default A leading global CRO Conclusion This macro significantly enhance SAS axis ordering mechanism, especially for procedures like GPLOT, GCHART. In generally cases, it will generate axis order better than SAS default for procedures like GPLOT/GCHART, and comparable or better than axis ordering mechanism in SAS9.3 STAT graph package and SAS9.3 GTL graph package. A leading global CRO