gce solutions - lex jansen · derive value from excellence… array reference array-name...

18
Derive value from excellenceG - Siddharth Kumar, Principal Programmer GCE SOLUTIONS Add Derived Parameters using Multi-Dimensional Arrays

Upload: others

Post on 20-May-2020

16 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…

G -

Siddharth Kumar, Principal Programmer

GCE SOLUTIONS

Add Derived Parameters using Multi-Dimensional Arrays

Page 2: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

Page 3: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

Agenda

q TheSyntaxq TheProcessq Mul3dimensionalarrayq Situa3on–Solu3onq LaboratoryAnalysisDataset

q Func3onsq Conclusion

Page 4: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

Introduc.on

q WhendoweuseArrays:ü Performsameac3onsonmul3plevariables

ü Arrayallowstogroupabunchofvariablesforthesameprocess

ü Thehugeblockoftherepe33ousstatementsandredundantcalcula3oncodescanbereducedtojustafewlines

ü Codecanbesimplifiedwiththeuseofarrays

q Derive/UpdateTreatmentVariablesinAnalysisDataset

q Derive/UpdateAnalysisFlagVariables(anl01fl,..)inAnalysisDataset

q ConcatenateandApplyFormattoalltheTreatmentVariablesforpresenta3oninOutput

Page 5: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

TheSyntaxarrayarray-name{n}<$><length>array-elements<(ini3alvalues)>;q array-name–AnyvalidSASnamethatiden3fiesthegroupof

variablesq n–Numberofelementswithinthearrayq $-Indicatestheelementswithinthearrayarecharacter

typevariablesq Length–assignslengthforthearrayelementsq Elements–ListofSASvariablestobepartofthearrayq  Ini3alvalues–Providestheini3alvaluesforeachofthe

arrayelements.

Page 6: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

ArrayReferencearray-name{subscript}q Wherearray-name-isthenameofanarraythatwaspreviously

definedwithARRAYstatementinthesameDATAstep.q  Subscript-specifiesthesubscript,whichcanbeanumeric

constant,thenameofavariablewhosevalueisthenumber,aSASnumericexpression,oranasterisk(*).

q  Anarraymustbedefinedwithinthedatasteppriortobeingreferenced.

q  Arrayexistsonlyforthedura3onofthedatastepinwhichtheyaredefined

Page 7: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

Mul.DimensionalArrayorNestedArray

q Mul3dimensionalarraysareusedwhenyouwanttogroupdataorputvaluesina‘tablelike’format(i.e.,rowsandcolumns).

q  Thedimensionsofarraysworkslikethefollowing:ü  One-dimensionalarray:arrayx(cols)ü  Two-dimensionalarray:arrayy(rows,cols)ü  Three-dimensionalarray:arrayz(levels,rows,cols).

q  Thenumberofelementsareplacedineachdimensionacerthearraynameintheform{n,..}.

q  Fromrighttolec,therightmostdimensionrepresentscolumns;thenextdimensionrepresentsrows.Eachposi3onfartherlecrepresentsahigherdimension.

Page 8: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

Mul.DimensionalArrayorNestedArraymyArray{4,6}lab1-lab6hem1-hem6hist1-hist6chem1-chem6;

Variable ArrayReference

Hist3 myArray{3,3}

hem3 myArray{2,3}

Lab1 Lab2 Lab3 Lab4 Lab5 Lab6Hem1 Hem2 Hem3 Hem4 Hem5 Hem6Hist1 Hist2 Hist3 Hist4 Hist5 Hist6Chem1 Chem2 Chem3 Chem4 Chem5 Chem6

Page 9: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

ExampleofdatasetwhenOne-Dimensional&Two-Dimensionalarraysareapplied

Page 10: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

DoLoop

Doi=1to4;*row;doj=1to6;*column

ifmyArray[i,j]>80thenmyArray[i,j]=.;end;end;• Mul3dimensionalarraysareusuallyprocessedinsidenestedDoloops.

•  Adoloopisneededforeachdimension•  onefortherows(whichisrepresentedbyiandsetfrom1to4).ThisDoloopprocessestheinnerDoloopfour3mes.

•  oneforthecolumns(representedbyjandsetfrom1to6).ThisDoloopappliesthederiva3ontoallthevariablesinonerow.

•  Note,ifyoumakeireferencetherows(1to4),thatiisputinthefirstposi3oninthearrayreference.

•  Anarrayreferencecanusetwoormoreindexvariablesasthesubscripttorefertotwoormoredimensionsofanarray.

Page 11: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

ProgrammingSpecifica.ons

11

Page 12: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

GivenData

12

Page 13: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

TheCode

1313

Doloopfortherows(whichisrepresentedbyjandsetfrom1to4)

Doloopforthecolumn(whichisrepresentedbyiandsetfrom1to5)

Page 14: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

TheOutput

1414

AddedData

Page 15: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

Func.ons:Dim,Lbound,Hbound•  DeterminingtheNumberofElementsinanArrayEfficiently

•  DIMreturnsthenumberofelementsinanarraydimension.•  HBOUNDreturnsthevalueoftheupperboundofanarraydimension.•  LBOUNDreturnsthevalueofthelowerboundofanarraydimension.

•  formoftheDIMfunc3onis:DIMn(array-name)

•  LBOUNDfunc3on:LBOUNDn(array-name)•  HBOUNDfunc3ons:HBOUNDn(array-name)

•  wherenisthespecifieddimensionthathasadefaultvalueof1.Example:arraymult{2:6,4:13,2}mult1-mult100;

Syntax Alterna.veSyntax Value

HBOUND(MULT) HBOUND(MULT,1) 6 HBOUND2(MULT) HBOUND(MULT,2) 13

HBOUND3(MULT) HBOUND(MULT,3) 2

Page 16: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

UseofFunc.onsDIM,LBOUND&HBOUNDINMULTI-DIMENSIONALARRAY

16

Useoffunc3onDIM

Useoffunc3onLBOUND&HBOUND

Page 17: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

Conclusion

q INNOVATIONq AUTOMATION

ü Easiertomaintainandupdateü Easiertoaddnewcriteria

q MOTIVATION• MinimizetheCode,SaveTimeandEfforts• Effec3veuseofMul3-DimensionalArraysorNestedArrayscanincreaseEFFICIENCYofprogram.

Page 18: GCE SOLUTIONS - Lex Jansen · Derive value from excellence… Array Reference array-name {subscript} q Where array-name - is the name of an array that was previously defined with

Derivevaluefromexcellence…Derivevaluefromexcellence…

THANKYOU________________________________________

18

AnyQUESTIONS