SAS® Functions/Informats/Formats    

          Training Videos:

Which comes first PUT() or the INPUT()? (Summary Sheet)


SAS® functions (character, numeric, and date) play a vital role in creating variables.  When comparing character variables or constants, it is often helpful to apply functions such as LOWCASE(), UPCASE() or PROPCASE() to standardize character text.  

Below are a collection of SAS® papers on functions, informats and formats.  PUT() using a user defined character format for example, is useful for table lookup feature.  See Which comes first PUT() or the INPUT()? training session.  See my SAS tip on Put() and Input() on SAS blog.

SAS 9.2 On-Line: InformatsFormatsFunctionsFunctions by CategoryLists

Lookup Reference  Favorite SAS Function Blog

 Type of SAS Functions

 CHARACTER / TRUNCATION, NUMERIC / MATHEMATICAL, DATE / TIME, STATISTICAL, SYSTEM, FINANCIAL, PROBABILITY, RANDOM NUMBER, STATE/ZIP CODE, ARRAY, QUANTILE and SPECIAL

 
Purpose of SAS Functions

 Convert variable types, Create variables, Convert variables, Find/Count/Compare Single/Word character values, Verify Values, Control blanks in character values, Length, Upper/Lower Case, Substring character values, Concatenate/Replace character values, Date/Time Components, Date Intervals, Descriptive Statistics, Numeric Calculations 


See also Data Step, Proc Format, Clinical Data Management, SAS Version 9.2 and SAS Dates.












 SAS® Character Functions

Result 
 COUNTW('this is my house')

 4 
 LOWCASE('this is my house')

 this is my house 
 UPCASE('this is my house')

 THIS IS MY HOUSE
 PROPCASE('this is my house')

 This Is My House

 visitlbl = strip(visitlbl)||' '||strip(substr(labtest_,
index(labtest_, 'hour') -3));

 Day 1 12
 
Dataset ID Functions (Generally processed with Do-Loop macros for each variable and %SCAN for list of values)

Result 
 %LET DSID=%SYSFUNC(OPEN(STUDYLIB.&IN_DS));  A number to reference dataset instead of the dataset name. 

 %LET VARLAB=%SYSFUNC(VARLABEL(&DSID, &VARPOS));  Returns the variable's label.

 %LET VARLEN=%SYSFUNC(VARLEN(&DSID, &VARPOS));  Returns the variable's length.

 %LET VARTYPE=%SYSFUNC(VARNAME(&DSID, &VARPOS));  Returns the variable's name.

 %LET VARPOS=%SYSFUNC(VARNUM(&DSID, AGE)); Returns AGE's position number. 

 %LET VARTYPE=%SYSFUNC(VARTYPE(&DSID, &VARPOS));  Returns variable type = C or N.

LEAD to bring next record to current record

 

LAG() and DIF() functions process data across records like SAS procedures


 
PATNO

WEIGHT 

LAG(WEIGHT) 

DIF(WEIGHT) 
 
Comments - See SAS Paper, Syntax

 101

100 

Missing

 101

110

100 

 10 Difference from previous record's value, useful to calculate change from previous value

______________________________________________

Beginner Function Paper An Introduction to SAS® Character Functions, Ron Cody [Data Cleaning]

Scope of Function Paper A Survey of Some of the Most Useful SAS® Functions
Ron Cody

Variety of SAS Function Paper Using SAS Functions in Data Steps, Yue Ye, Yong Lin

SAS Reference  SAS V 9 Character Functions

SAS Book Examples SAS Functions by Example

An Animated Guide: Using the Put and INput functions, Russ Lavery

Understanding and Using Functions, Frank DiIorio (Table of Functions)

INTNX and INTCK Function Examples SAS Blog

 ______________________________________________

1. Data Cleaning and Base SAS Functions, Caroline Bahler

2. Benchmarking Character String Replacement, Bruce Gilsen

3. Retaining, Lagging, Leading, and Interleaving Data, Toby Dunn, Chang Y. Chung

4. An Introduction to Perl Regular Expressions in SAS 9, Ron Cody

5. Learning to love the SAS LAG function, H. Ament [LAG(), LAG2(), LAG3(), Dif Function]

6. “LAG With a WHERE” and Other DATA Step Stories, Neil Howard

7. Using and Understanding SAS@ Formats, Howard Levine

8. Discovering the FUN in SAS Functions, Neil Howard

9. Using and Understanding SAS@ Formats, Howard Levine

10. Handling Dynamic Variable Types in SAS®, Venkat Lajapathirajan

11. IFC and IFN Functions: Alternatives to Simple DATA Step 
IF-THEN-ELSE, SELECT-END Code and PROC SQL CASE Statements, Thomas Billings
 [SAS Blog]

12. Introduction to SAS Functions, Neil Howard

13. Fully “Function”-al: A Brief Tour of Selected SAS® Numeric Functions, Brenda Beaty [CMISS]

14. Working with Character Data, Andrew Kuligowski, Swati Agarwal [CATX, Narratives]

15. Using PROC FCMP to the Fullest: Getting Started and Doing More, Arthur Carpenter [Manual, Proc Format]

16. Using SAS® PROC FCMP in SAS® System Development - Real Examples, Yves Deguire, Xiyun Wang

17. A Cup of Coffee and Proc FCMP: I Cannot Function Without Them, Peter Eberhardt [Presentation]

18. Helpful Undocumented Features in SAS®, Wei Cheng [INDEXW()] [SAS Support]

19. Dressing for success with SAS® Software Functions, Faith Sloan

20. See SAS blog to help remember PUT() and INPUT()

21. Building and Using User Defined Formats, Art Carpenter [Table Lookup. Proc Format]

22. What’s the DIF?,Nikki Carroll

23. LAG - the Very Powerful and Easily Misused SAS® Function,Yunchao Tian [DIF function]

24. Longitudinal Data Techniques: Looking Across Observations, Ronald Cody [LAG(), DIF function]

25. Proc FCMP Guide

26. The new SAS 9.2 FCMP Procedure, what functions are in your future?, John H. Adams

27. Those Sneaky SAS® Functions: Beware of Unexpected Handling of Missing Data and Variable Lists, Christianna Williams

28. Please Don't Lag Behind LAG!, Anjan Matlapudi and J. Daniel Knapp [Proc SQL]

29. LEADS AND LAGS: HANDLING QUEUES IN THE SAS® DATA STEP, Mark Keintz [Impute Macro, FIRST.]

30. Can you read this into SAS® for me? “Using INFILE and INPUT to Load Data Into SAS, Peter Eberhardt, Audrey Yeo

31. Fun with Functions, Yogini Thakkar [INDEX, INDEXC, INDEXW, FIND, FINDC]

32. A Clever Demonstration of the SAS® SUBSTR Function, David Austin [INDEX, nested]

33. Matching Data Using Sounds-Like Operators and SAS Compare Functions, Amanda Roesch [SOUNDEX]

34. Introduction to Character String Functions, Jason Ford 

35. The SAS SUBSTR Function – A Beginner’s Tutorial, Paul D. McDonald

36. SAS® Functions - Simple But Powerful Techniques, Steve Holson, Jenny Putman

37. (In)Formats (In)Decently Exposed, Harry Droogendyk [Scientific Notation]

38. Captain LOG: Taking Command of SAS Logarithm Functions, Britney Gilbert, Joshua Horstman

39. Utilizing SAS Functions to Access Variable Information, Joleen Borgerding, Akiko Chai [VARNUM, VARNAME]

40. Programming with SAS® Functions, with a Special Emphasis on SAS® Dates and Times, Ann Doty

41. SAS® Date and Time Functions 101, Nikki Carroll

42. Hanging On By a STRING? Using Functions To Untie Text Strings, Jeanina Worden [SCAN]

43. Seek and Ye Shall FINDC; A Powerful Function for Qualitative Data Validation, Xiaoke Yang and Peter Landi

44. Direct Memory Data Management Using the APP Tools, Paul Dorfman

45. When ANY Function Will Just NOT Do, Richann Watson [Presentation]

46. Fifteen Functions to Supercharge Your SAS® Code Joshua M. Horstman

47. LAG Function Combined with Conditional Functions – Useful in Identifying Differences in Like Data, Andy Hummel

48. Creating Code writing algorithms for producing n-lagged variables, Matt Bates

49. The COMPRESS Function: Hidden Superpowers, Pamela Reading

50. FCMP: A Powerful SAS® Procedure You Should Be Using, Bill McNeill, Andrew Henrick, Mike Whitcher, and Aaron Mays

51. Address Cleaning Using the TRANWRD Function, Rena Jones, Mike Zdeb [TRANSLATE]

52. Search and Replace in SAS Data Sets thru GUI, Edmond Cheng [TRANWRD]

53. TRANSLATE Function blog

54. Squeezing Information out of Data, William Murphy [COMPRESS]

55. The Basics of the PRX Functions, David Cassell [Perl]

56. Some Simple Perl Regular Expressions Examples in SAS 9, Selvaratnam Sridharma

57. Compress It More, Linda Simonsson [Remove carriage control - Text2=compress(Text,,'kw');]

58. Non-Printable and Special Characters? … BYTE me!, Louise Sims [Presentation]

59. Line Feeds – How to detect them and get rid of them?, Kalyani Kothapalli

60. Colonoscopy for the SAS® Programmer, William Murphy

63. Dealing with Blanks: Leading, Trailing, In-Between, Virginia Chen

64. Line Feeds – How to detect them and get rid of them?, Kalyani Kothapalli

65. Using Invisible Characters in SAS Programming, Hidden Dragons, Shi-Tao Yeh

66. Advanced Programming Techniques for Working with Color in SAS Software, Perry Watts [HEX format]

67. Special Missing Values for Character Fields, John Ladds [HEX format]

68. Hexadecimals in SAS: Have You Been Hexed?, Imelda Go

69. Rounding in SAS: Preventing Numeric Representation Problems, Imelda Go

70. Translation tables: myth and reality, Philippe Jalbert, Normand Létourneau, Dominic Roy, Jean Hardy

71. Unleash the Power of Less Well Known but Useful SAS® DATA Step Functions, Timothy Harrington

72. User-Written DATA Step Functions, Jason Secosky

73. Getting the IN operator to FUNCTION inside a SAS® Macro, Perry Watts

74. Automatically Converting Character Variables That Store Numbers to Numeric Variables Christopher Bost

75. A Note on Type Conversions and Numeric Precision in SAS: Numeric to character and back again, Andrew Clapson

76. Custom useful SAS functions using the PROC FCMP procedure, Qixia Shi, Guanyu [Study Day, BMI, Valid Numeric]

Powered by Wild Apricot Membership Software