Introducing the COLON Graham Stott Tip: Introducing the COLON - - PowerPoint PPT Presentation

introducing the colon
SMART_READER_LITE
LIVE PREVIEW

Introducing the COLON Graham Stott Tip: Introducing the COLON - - PowerPoint PPT Presentation

Introducing the COLON Graham Stott Tip: Introducing the COLON Graham Stott Independent SAS Consultant 0432786140 | Graham@gstott.com Tip: Introducing the COLON SAS uses the colon : in many places Key ones are: When reading input files


slide-1
SLIDE 1

Introducing the COLON Graham Stott

slide-2
SLIDE 2

Tip: Introducing the COLON

Graham Stott Independent SAS Consultant 0432786140 | Graham@gstott.com

slide-3
SLIDE 3

Tip: Introducing the COLON

SAS uses the colon : in many places Key ones are:

  • When reading input files (the format modifier)
  • Used in SQL to assign values to macro variables
  • In arrays to define the amount of array items needed
  • As a wildcard indicator
  • A label
  • Text searching

... And quite a few more …

slide-4
SLIDE 4

String Comparisons

  • Using hardcoding or complex functions to parse strings?
  • Use the colon as a wildcard indicator when comparing instead
  • The colon can follow all operators (=:, >=:,<=:, ne:, gt:, lt:, in:). The following 'in:'
  • peration will select any string starting with A1, B2 or G5

If mytext in (’HL224’,’HL533’,’HL333’) then do; If substr(mytext,1,2) = ’HL’ then do; If mytext=:’HL’ then do; if mytext in:(’A1’,’B2’,’G5’) then do;

slide-5
SLIDE 5

A Wildcard Indicator

  • When listing variables in drop and keep statements
  • Use the colon to enable the use of a prefix to reference multiple variables

Data mydset (drop=A3 A4 A7 A8 A10-A16 B1 C4 C6 D4); Data mydset (drop=A: B: C: D4); Data newData(keep=A1:); Total=sum(of month:);

slide-6
SLIDE 6

Dynamic Macro Variables

  • An alternative to call symput, creating macro variables via proc SQL
  • More than one variable? No problem
  • A list of values?

Proc SQL noprint; Select MaxVal format=12.0 into :MaxVal from myLib.myData; Quit; Select Value1, Value2 into :Val1, :Val2 from myLib.myData; Select products into :prodList separated by "," from myLib.myData;