2018-09-21 1 Copyright 2018 Peter Eberhardt, Fernwood Consulting Group Inc. All rights Reserved. TASS Functioning at a Higher Level: Using SAS® Functions to Improve Your Code Peter Eberhardt Fernwood Consulting Group Inc. Lucheng Shao Ivantis, Inc Copyright 2018 Peter Eberhardt, Fernwood Consulting Group Inc. All rights Reserved. Functioning at a Higher Level: Using SAS® Functions to Improve Your Code Peter Eberhardt
17
Embed
Functioning at a Higher Level: to Improve Your Codetorsas.ca/attachments/File/20180914/Functions Peter Eberhardt 201… · 2018-09-21 3 Copyright 2018 Peter Eberhardt, Fernwood Consulting
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
2018-09-21
1
Copyright 2018 Peter Eberhardt, Fernwood Consulting Group Inc. All rights Reserved.
TASS
Functioning at a Higher Level:Using SAS® Functionsto Improve Your Code
Peter EberhardtFernwood Consulting Group Inc.
Lucheng ShaoIvantis, Inc
Copyright 2018 Peter Eberhardt, Fernwood Consulting Group Inc. All rights Reserved.
Functioning at a Higher Level: Using SAS® Functions to Improve Your Code
Peter Eberhardt
2018-09-21
2
Copyright 2018 Peter Eberhardt, Fernwood Consulting Group Inc. All rights Reserved.
Functioning at a Higher Level: Using SAS® Functions to Improve Your Code
Agenda
• Examples• Examples• Yet more examples
• Run out of time
Copyright 2018 Peter Eberhardt, Fernwood Consulting Group Inc. All rights Reserved.
Functioning at a Higher Level: Using SAS® Functions to Improve Your Code
What is a Function
2018-09-21
3
Copyright 2018 Peter Eberhardt, Fernwood Consulting Group Inc. All rights Reserved.
Functioning at a Higher Level: Using SAS® Functions to Improve Your Code
FunctionMain Entry: 1func·tionPronunciation: \ˈfəŋ(k)-shən\Function: nounEtymology: Latin function-, functio performance, from fungi to
perform; probably akin to Sanskrit bhuṅkte he enjoys
1: professional or official position : occupation2: the action for which a person or thing is specially fitted or
used or for which a thing exists : purpose3: any of a group of related actions contributing to a larger action
; especially : the normal and specific contribution of a bodilypart to the economy of a living organism
Source: Mirriam-Webser Online
Copyright 2018 Peter Eberhardt, Fernwood Consulting Group Inc. All rights Reserved.
Functioning at a Higher Level: Using SAS® Functions to Improve Your Code
FunctionMain Entry: 1func·tion4: an official or formal ceremony or social gathering5a: a mathematical correspondence that assigns exactly one
element of one set to each element of the same or another set5b: a variable (as a quality, trait, or measurement) that depends on
and varies with another <height is a function of age> ; also : result<illnesses that are a function of stress>
6: characteristic behavior of a chemical compound due to aparticular reactive unit ; also : functional group
2018-09-21
4
Copyright 2018 Peter Eberhardt, Fernwood Consulting Group Inc. All rights Reserved.
Functioning at a Higher Level: Using SAS® Functions to Improve Your Code
FunctionMain Entry: 1func·tion7: a computer subroutine ; specifically : one that performs a
calculation with variables provided by a program and supplies theprogram with a single result
Copyright 2018 Peter Eberhardt, Fernwood Consulting Group Inc. All rights Reserved.
Functioning at a Higher Level: Using SAS® Functions to Improve Your Code
What is a function
• The SAS online help has this definition :A SAS function performs a computation
or system manipulation on arguments,and returns a value that can be used inan assignment statement or elsewherein expressions
2018-09-21
5
Copyright 2018 Peter Eberhardt, Fernwood Consulting Group Inc. All rights Reserved.
Functioning at a Higher Level: Using SAS® Functions to Improve Your Code
Copyright 2018 Peter Eberhardt, Fernwood Consulting Group Inc. All rights Reserved.
Functioning at a Higher Level: Using SAS® Functions to Improve Your Code
Character• CAT family
– Concatenate variables– Replaces the || operator with trim() and/or left()
2018-09-21
13
Copyright 2018 Peter Eberhardt, Fernwood Consulting Group Inc. All rights Reserved.
Functioning at a Higher Level: Using SAS® Functions to Improve Your Code
Character• CAT family
– Cat()• Concatenates, does not remove blanks
– Catq()• Concatenates using delimter plus many options
– Catt()• Concatenates, removes trailing blanks
– Cats()• Concatenates and removes blanks
– Catx()• Concatenates and removes blanks inserts delimiter
Copyright 2018 Peter Eberhardt, Fernwood Consulting Group Inc. All rights Reserved.
Functioning at a Higher Level: Using SAS® Functions to Improve Your Code
Characterdata catInHat;var1 = "I do "; var2 = "not eat";var3 = "green eggs"; var4 = " and ham";line = var1 || var2 || var3 || var4;lineCat = cat( of var:);lineCats = cats( of var:);lineCatt = catt( of var:);lineCatq = catq(' ', of var:);lineCatx = catx(' ', of var:);put 'line ' line;put 'lineCat= ' lineCat;put 'lineCats= ' lineCats;put 'lineCatt= ' lineCatt;put 'lineCatq= ' lineCatq;put 'lineCatx= ' lineCatx;
run;
2018-09-21
14
Copyright 2018 Peter Eberhardt, Fernwood Consulting Group Inc. All rights Reserved.
Functioning at a Higher Level: Using SAS® Functions to Improve Your Code
Characterdata catInHat;var1 = "I do "; var2 = "not eat";var3 = "green eggs"; var4 = " and ham";
line I do not eatgreen eggs and hamlineCat= I do not eatgreen eggs and hamlineCats= I donot eatgreen eggsand hamlineCatt= I donot eatgreen eggs and hamlineCatq= "I do " "not eat" "green eggs" " and ham"lineCatx= I do not eat green eggs and ham
Copyright 2018 Peter Eberhardt, Fernwood Consulting Group Inc. All rights Reserved.
Functioning at a Higher Level: Using SAS® Functions to Improve Your Code