Sas Functions By Example Second Edition 2nd Ron Cody
Sas Functions By Example Second Edition 2nd Ron Cody
Sas Functions By Example Second Edition 2nd Ron Cody
Sas Functions By Example Second Edition 2nd Ron Cody
1. Sas Functions By Example Second Edition 2nd Ron
Cody download
https://ebookbell.com/product/sas-functions-by-example-second-
edition-2nd-ron-cody-2540302
Explore and download more ebooks at ebookbell.com
2. Here are some recommended products that we believe you will be
interested in. You can click the link to download.
Proc Fcmp Userdefined Functions An Introduction To The Sas Function
Compiler Troy Martin Hughes
https://ebookbell.com/product/proc-fcmp-userdefined-functions-an-
introduction-to-the-sas-function-compiler-troy-martin-hughes-56693560
Sasaccess 913 For Relational Databases Reference 3rd Edition 3rd
Edition The Sas Technical Team Writers
https://ebookbell.com/product/sasaccess-913-for-relational-databases-
reference-3rd-edition-3rd-edition-the-sas-technical-team-
writers-2161692
Sas 91 National Language Support Users Guide 2004 The Sas Technical
Team Writers
https://ebookbell.com/product/sas-91-national-language-support-users-
guide-2004-the-sas-technical-team-writers-2162298
Sas Access 913 Supplement For Mysql Sas Access For Relational
Databases The Sas Technical Team Writers
https://ebookbell.com/product/sas-access-913-supplement-for-mysql-sas-
access-for-relational-databases-the-sas-technical-team-writers-2162690
3. Sas Access 91 Supplement For Informix Sas Access For Relational
Databases The Sas Technical Team Writers
https://ebookbell.com/product/sas-access-91-supplement-for-informix-
sas-access-for-relational-databases-the-sas-technical-team-
writers-2163250
Sas 91 Sql Procedure Users Guide The Sas Technical Team Writers
https://ebookbell.com/product/sas-91-sql-procedure-users-guide-the-
sas-technical-team-writers-2191522
Getting Started With Sas Profitability Management 13 Sas Publishing
https://ebookbell.com/product/getting-started-with-sas-profitability-
management-13-sas-publishing-2201734
Sas Certification Prep Guide Base Programming For Sas 9 Sas
https://ebookbell.com/product/sas-certification-prep-guide-base-
programming-for-sas-9-sas-2479456
Sas And Special Forces Self Defence Handbook John Lofty Wiseman
https://ebookbell.com/product/sas-and-special-forces-self-defence-
handbook-john-lofty-wiseman-43600788
8. Contents
List of Programs vii
Preface to the Second Edition xix
Preface to the First Edition xxi
Acknowledgments xxiii
Introduction xxv
Chapter 1 Character Functions 1
Introduction 3
Functions That Change the Case of Characters 5
Functions That Remove Characters from Strings 11
Functions That Search for Characters 16
Functions That Extract Parts of Strings 46
Functions That Join Two or More Strings Together 57
Functions That Remove Blanks from Strings 70
Functions That Compare Strings (Exact and "Fuzzy"
Comparisions 78
Functions That Divide Strings into "Words" 97
Functions That Substitute Letters or Words in Strings 106
Functions That Compute the Length of Strings 111
Functions That Count the Number of Letters or Substrings in a
String 114
Miscellaneous String Functions 121
Chapter 2 Perl Regular Expressions 143
Introduction 143
A Brief Tutorial on Perl Regular Expressions 144
Function That Defines a Regular Expression 150
Functions That Locate Text Patterns 152
Function That Substitutes One String for Another 168
Function That Releases Memory Used by a Regular Expression 171
9. iv Contents
Chapter 3 Sort Functions 173
Introduction 173
Function That Sorts Numeric Values 174
Function That Sorts Character Values 176
Chapter 4 Date and Time Functions 179
Introduction 180
Functions That Create SAS Date, Datetime, and Time Values 180
Functions That Extract the Year, Month, Day, etc., from a
SAS Date 188
Functions That Extract Hours, Minutes, and Seconds from SAS
Datetimes and Time Values 192
Functions That Extract the Date or Time from SAS Datetime
Values 195
Functions That Work with Date, Datetime, and Time Intervals 197
Function That Computes Dates of Standard Holidays 212
Functions That Work with Julian Dates 214
Chapter 5 Array Functions 219
Introduction 219
Chapter 6 Truncation Functions 225
Introduction 225
Functions That Round and Truncate Numerical Values 226
Function That Returns SAS Numerical Values Stored in Fewer
than 8 Bytes 234
Chapter 7 Descriptive Statistics Functions 237
Introduction 238
Functions That Determine the Number of Missing and Non-missing
Values in a List of SAS Variables 238
Functions That Compute Sums, Means, and Medians 241
Functions That Compute the Spread or Dispersion of
Data Values 244
Functions That Determine the Ordering of Data Values 247
10. Contents v
Chapter 8 Mathematical and Numeric Functions 267
Introduction 267
Commonly Used Mathematical Functions 268
Functions That Work with Exponentiation and Logarithms 276
Factorial and Gamma Functions 279
Miscellaneous Functions 282
Chapter 9 Random Number Functions 287
Introduction 287
Functions That Generate Uniform Random Numbers 290
Functions That Generate Normally Distributed Numbers 303
A Function That Generates Random Numbers from a Wide Variety of
Probability Distributions 310
Chapter 10 Special Functions 315
Introduction 315
Functions That Obtain Values from Previous Observations 315
Functions That Perform Character-to-Numeric or Numeric-to-
Character Conversion 321
Function That Sets Variable Values to a SAS Missing Value 333
Chapter 11 State and ZIP Code Functions 335
Introduction 335
Functions That Convert FIPS Codes 336
Functions That Convert State Codes 339
Functions That Convert ZIP Codes 341
Functions That Compute Geographical Distance 346
Chapter 12 Trigonometric Functions 351
Introduction 351
Three Basic Trigonometric Functions 351
Three Inverse Trigonometric Functions 355
Chapter 13 Macro Functions 359
Introduction 359
11. vi Contents
Chapter 14 SAS File I/O Functions 371
Introduction 371
Functions That Determine if SAS Data Sets Exist, and That Open
and Close Files 373
Functions That Return SAS Data Set Characteristics 375
Functions That Return Variable Information 381
Chapter 15 Variable Information Functions 391
Introduction 391
Functions That Determine SAS Variable Information 392
Functions That Determine Format Information 403
Functions That Determine Informat Information 406
Chapter 16 Bitwise Logical Functions 411
Introduction 411
List of Functions 421
Index 429
12. List of Programs
Chapter 1
Program 1.1: How SAS determines storage lengths of character variables 3
Program 1.2: Running PROC CONTENTS to determine storage lengths 4
Program 1.3: Changing lowercase to uppercase for all character variables
in a data set 6
Program 1.4: Program to demonstrate the LOWCASE function 8
Program 1.5: Capitalizing the first letter of each word in a string 9
Program 1.6: Program to capitalize the first letter of each word in a string 10
Program 1.7: Using the COMPBL function to convert multiple blanks to a
single blank 11
Program 1.8: Removing dashes and parentheses from phone numbers 13
Program 1.9: Converting Social Security numbers from character to
numeric 14
Program 1.10: Counting the number of digits in a string 15
Program 1.11: Demonstrating the "ANY" character functions 24
Program 1.12: Using the functions ANYDIGIT and ANYSPACE to find the
first number in a string 25
Program 1.13: Demonstrating the "NOT" character functions 31
Program 1.14: Using the FIND and FINDC functions to search for strings
and characters 35
Program 1.15: Converting numeric values of mixed units (e.g., kg and lbs)
to a single numeric quantity 36
Program 1.16: Searching for one of several characters in a character variable 37
13. viii List of Programs
Program 1.17: Demonstrating the o modifier with FINDC 38
Program 1.18: Searching for a word using the FINDW function 40
Program 1.19: Reading dates in a mixture of formats 43
Program 1.20: Using the VERIFY function to check for invalid character
data values 45
Program 1.21: Extracting portions of a character value and creating a
character variable and a numeric value 47
Program 1.22: Extracting the last two characters from a string, regardless
of the length 48
Program 1.23: Using the SUBSTR function to "unpack" a string 49
Program 1.24: Demonstrating the SUBSTR function on the left-hand side
of the equal sign 51
Program 1.25: Demonstrating the unique features of the SUBSTRN function 53
Program 1.26: Demonstrating the CHAR function 55
Program 1.27: Demonstrating the FIRST function 56
Program 1.28: Demonstrating the three concatenation CALL routines 61
Program 1.29: Demonstrating the five concatenation functions 68
Program 1.30: Left-aligning text values from variables read with the
$CHAR informat 71
Program 1.31: Right-aligning text values 72
Program 1.32: Creating a program to concatenate first, middle, and last
names into a single variable 74
Program 1.33: Demonstrating the difference between the TRIM and TRIMN
functions 76
Program 1.34: Using the STRIP function to strip both leading and trailing
blanks from a string 77
Program 1.35: Comparing two strings using the COMPARE function 80
Program 1.36: Using the COMPGED function with a SAS n-literal 84
14. List of Programs ix
Program 1.37: Demonstration of the generalized edit distance (COMPGED)
and Levenshtein edit distance (COMPLEV) functions 86
Program 1.38: Changing the effect of the call to COMPCOST on the result
from COMPGED 88
Program 1.39 Fuzzy matching on names using the SOUNDEX function 90
Program 1.40: Using the SPEDIS function to match Social Security
numbers that are the same or differ by a small amount 94
Program 1.41: Fuzzy matching on names using the spelling distance
(SPEDIS) function 95
Program 1.42: A novel use of the SCAN function to convert mixed
numbers to decimal values 100
Program 1.43: Program to read a tab-delimited file 101
Program 1.44: Alphabetical listing by last name when the name field
contains first name, possibly middle initial, and last name 101
Program 1.45: Demonstrating the SCAN CALL routine 104
Program 1.46: Using CALL SCAN to count the words in a string 105
Program 1.47: Converting values of '1','2','3','4', and '5' to 'A','B','C','D', and
'E' respectively 107
Program 1.48: Converting the values "Y" and "N" to 1's and 0's 108
Program 1.49: Converting words such as Street to their abbreviations
such as St. in an address 110
Program 1.50: Demonstrating the LENGTH, LENGTHC, LENGTHM, and
LENGTHN functions 113
Program 1.51: Using the COUNT function to count the number of times the
word "the" appears in a string 115
Program 1.52: Demonstrating the COUNTC function to find one or more
characters or to check if characters are not present in a string 117
Program 1.53: Demonstrating the COUNTW function 120
15. x List of Programs
Program 1.54: Using the CHOOSEC function to randomly select one of
three reviewers for each candidate (numbered 1 to n) 122
Program 1.55: Using CHOOSEN to randomly select a reviewer (by
number) for each of n candidates 124
Program 1.56: Determining if there are any missing values for all variables
in a data set 126
Program 1.57: Demonstrating the MISSING function with .A, .B, etc.
numeric values 127
Program 1.58: Demonstrating the COALESCEC function 129
Program 1.59: Using the IFC function to select a character value, based
on the value of a logical expression 130
Program 1.60: Using the collating sequence to convert plain text to Morse
Code 132
Program 1.61: Using the REPEAT function to underline output values 134
Program 1.62: Using the REVERSE function to create backwards writing 135
Program 1.63: Demonstrating the NLITERAL function 137
Program 1.64: Demonstrating the NVALID function 139
Program 1.65: Using the NVALID function to count the number of valid
V7 and non-valid V7 variable names in a data set 141
Chapter 2
Program 2.1: Using a Perl regular expression to locate lines with an exact
text match 145
Program 2.2: Using a regular expression to search for phone numbers in a
string 153
Program 2.3: Modifying Program 2.2 to search for toll-free phone numbers 154
Program 2.4: Using PRXMATCH without PRXPARSE (entering the regular
expression directly in the function) 155
Program 2.5: Locating all 5- or 9-digit ZIP codes in a list of addresses 157
16. List of Programs xi
Program 2.6: Extracting a phone number from a text string 159
Program 2.7: Using the PRXPOSN CALL routine to extract the area code
and exchange from a phone number 161
Program 2.8: Using regular expressions to read very unstructured data 162
Program 2.9: Finding digits in random positions in an input string using
CALL PRXNEXT 165
Program 2.10: Demonstrating the PRXPAREN function 166
Program 2.11: Demonstrating the CALL PRXCHANGE function 169
Program 2.12: Demonstrating the use of capture buffers with PRXCHANGE 170
Program 2.13: Data cleaning example using PRXPARSE and
CALL PRXFREE 171
Chapter 3
Program 3.1: Program to grade quizzes, dropping the two lowest quiz
scores (using CALL SORTN) 174
Program 3.2: Another example of CALL SORTN using array elements as
the arguments 175
Program 3.3: Demonstrating the CALL SORTC routine 177
Chapter 4
Program 4.1: Creating a SAS date value from separate variables
representing the day, month, and year of the date 181
Program 4.2: Program to read in dates and set the day of the month to
15 if the day is missing from the date 182
Program 4.3: Determining the date, datetime value, and time of day 186
Program 4.4: Program to create the DATES data set 187
Program 4.5: Demonstrating the functions YEAR, QTR, MONTH, WEEK,
DAY, and WEEKDAY 191
Program 4.6: Demonstrating the HOUR, MINUTE, and SECOND functions 194
17. xii List of Programs
Program 4.7: Extracting the date part and time part of a SAS datetime value 196
Program 4.8: Demonstrating the INTNX function (with the SAMEDAY
alignment) 207
Program 4.9: Program to demonstrate the date interval functions 210
Program 4.10: Demonstrating the HOLIDAY function 213
Program 4.11: Demonstrating the three Julian date functions 216
Chapter 5
Program 5.1: Setting all numeric values of 999 to missing and all
character values of 'NA' to missing 220
Program 5.2: Creating a macro to compute and print out the number of
numeric and character variables in a SAS data set 222
Program 5.3: Determining the lower and upper bounds of an array
where the array bounds do not start from one 223
Chapter 6
Program 6.1: Using the CEIL function to round up a value to the next penny 226
Program 6.2: Computing a person's age as of his or her last birthday
(rounding down) 228
Program 6.3: Using the INT function to compute age as of a person's last
birthday 229
Program 6.4: Rounding students' grades several ways 231
Program 6.5: Using the ROUND function to group ages into 10-year
intervals 232
Program 6.6: Demonstrating the various truncation functions 233
Program 6.7: Logical comparisons with numbers stored with fewer than
8 bytes of precision 235
18. List of Programs xiii
Chapter 7
Program 7.1: Using the N function to determine the number of
non-missing values in a list of variables 239
Program 7.2: Computing a SUM and MEAN of a list of variables, only if
there are no missing values 240
Program 7.3: Computing a mean, median, and sum of eight variables, only
if there are at least six non-missing values 243
Program 7.4: Computing a range, interquartile range, and standard
deviation for each subject 246
Program 7.5: Program to read hourly temperatures and determine the
daily minimum and maximum temperature 248
Program 7.6: Computing the three lowest golf scores for each player
(using the SMALLEST function) 250
Program 7.7: Computing a grade based on the five highest scores 252
Program 7.8: Macro to compute an average of n scores where the lowest
m scores are dropped 253
Program 7.9: Using the PCTL function to determine 25th, 50th, and 75th
percentile in a list of values 256
Program 7.10: Program to compute a quiz grade by dropping none, one, or
two of the lowest quiz scores, depending on how many
quizzes were taken 258
Program 7.11: Alternate version of Program 7.10 260
Program 7.12: Sorting values within an observation 261
Program 7.13: Macro to sort values within an observation 263
Program 7.14: Performing a t-test where values for each group are in a
single observation 265
19. xiv List of Programs
Chapter 8
Program 8.1: Determining mathematical constants and machine
constants using the CONSTANT function 269
Program 8.2: Using the MOD function to choose every nth observation
from a SAS data set 271
Program 8.3: Using the MOD function as a toggle switch, alternating
group assignments 272
Program 8.4: Computing chi-square with Yates' correction, which
requires an absolute value 274
Program 8.5: Program to compute and print out a table of integers and
square roots 275
Program 8.6: Creating tables of integers, their base-10 and base e
logarithms and their value taken to the nth power 278
Program 8.7: Creating a table of integers and factorials 280
Program 8.8: Demonstrating the GAMMA function 281
Program 8.9: Demonstrating the IFN Function 283
Program 8.10: Demonstrating the COALESCE function 284
Chapter 9
Program 9.1: Demonstrating differences between random functions and
CALL routines (function example) 288
Program 9.2: Demonstrating differences between random functions and
CALL routines (CALL routine example) 289
Program 9.3: Selecting an approximate n% random sample 291
Program 9.4: Selecting a random sample with exactly n observations 292
Program 9.5: Simulating random throws of two dice 292
Program 9.6: Randomly assigning n subjects into two groups: Method 1▬
Approximate number of subjects in each group 294
20. List of Programs xv
Program 9.7: Randomly assigning n subjects into two groups: Method 2▬
Equal number of subjects in each group 295
Program 9.8: Randomly assigning n subjects into two groups: Method 3▬
Equal number of subjects in each group within blocks of four
subjects 297
Program 9.9: Macro to assign n subjects into k groups 299
Program 9.10: Macro to assign n subjects into k groups, with b subjects
per block 301
Program 9.11: Demonstrating a Monte Carlo simulation to determine the
power of a t-test 304
Program 9.12: Program to generate random values of heart rates that are normally
distributed 309
Program 9.13: Generating a series of normally distributed values using the
RAND function 313
Chapter 10
Program 10.1: Using the LAGn functions to compute a moving average 317
Program 10.2: Computing changes in blood pressure from one visit to another 318
Program 10.3: Computing the difference in blood pressure between the
first and last visit for each patient 320
Program 10.4: Using the INPUT function to perform character-to-numeric
conversion 322
Program 10.5: Using the INPUTC function to specify an informat at run time 324
Program 10.6: Using the INPUTN function to read dates in mixed formats 326
Program 10.7: Performing a table look-up using a format and the PUT
function 328
Program 10.8: Using the PUTC function to assign a value to a character
variable at run time 330
21. xvi List of Programs
Program 10.9: Using the PUTN function to assign a value to a character
variable at run time 332
Program 10.10: Demonstrating the CALL MISSING routine 334
Chapter 11
Program 11.1: Converting FIPS codes to state names and abbreviations 338
Program 11.2: Converting state abbreviations to FIPS codes,
and state names 341
Program 11.3: Converting ZIP codes to FIPS codes, state names, and
state abbreviations 344
Program 11.4: Adding a state abbreviation to an address containing only
city and ZIP code 345
Program 11.5: Measuring the distance between two coordinates or two
ZIP codes 349
Chapter 12
Program 12.1: Creating a table of trigonometric functions 353
Program 12.2: Computing arccosines and arcsines 356
Program 12.3: Computing arctangents 358
Chapter 13
Program 13.1: Using the SYMPUT and SYMPUTX CALL routines to assign
a value to a macro variable during the execution of a DATA
step 362
Program 13.2: Passing DATA step values from one step to another, using
macro variables created by CALL SYMPUT and CALL
SYMPUTX 362
Program 13.3: Using RESOLVE to pass DATA step values to macro variables
during the execution of the DATA step 364
Program 13.4: Using CALL EXECUTE to conditionally execute a macro 366
Program 13.5: A non-macro example of CALL EXECUTE 367
22. List of Programs xvii
Program 13.6: Using the SYMGET function to assign a macro value to a
DATA step variable 369
Chapter 14
Program 14.1: Program to create two SAS data sets, TEST and MISS 372
Program 14.2: Macro to determine the number of observations in a SAS
data set 378
Program 14.3: Determining the number of observations, variables, and
other characteristics of a SAS data set using SAS I/O functions 380
Program 14.4: Determining the format, label, and length attributes of a
variable using the VARFMT, VARLEN, and VARNUM functions 384
Program 14.5: Determining a variable name, given its position in a SAS data set
and vice versa 386
Program 14.6: A general-purpose macro to display data set attributes such as
number of observations, number of variables, variable list, variable
type, formats, labels, etc. 387
Chapter 15
Program 15.1: Creating a test data set for use with most of the V functions 393
Program 15.2: Determining a variable's type (numeric or character) using
VTYPE and VTYPEX 394
Program 15.3: Determining the storage length of character and numeric
variables 395
Program 15.4: Program to replace all numeric values of 999 with a SAS missing
value and to provide a list of variable names where the changes
were made 396
Program 15.5: Writing a general-purpose macro to replace all occurrences of a
particular value (such as 999) to a SAS missing value and produce a
report showing the number of replacements for each variable 398
Program 15.6: Determining the name, type, and length of all variables in a SAS
data set 400
23. xviii List of Programs
Program 15.7: Demonstrating the VVALUE function 402
Program 15.8: Demonstrating a variety of SAS V functions 408
Chapter 16
Program 16.1: Demonstrating the bitwise logical functions 415
Program 16.2: Enciphering and deciphering text using a key 416
Program 16.3: Writing general-purpose encrypting and decrypting macros 418
24. Preface to the Second Edition
It is hard to believe that it's been over six years since the first edition of this book was published.
Although the major changes in SAS functions came with SAS®
9, many new functions have been
added to SAS since then, as well as additional capability added to old functions (such as new
arguments added to existing functions).
In this edition, I removed the chapter on SAS regular expressions and updated the chapter on Perl
regular expressions. I also added a new chapter on the two CALL routines that sort values within
an observation (CALL SORTN and CALL SORTC). As you will see in the examples of these
CALL routines, they can be extremely useful. In addition, features new to SAS 9.2 are noted.
Indeed, SAS has so many functions that it is hard for you to decide which functions are
indispensable and which ones you can do without. When I teach my Functions course, I like to
list what I call the "blockbuster" functions—those that change the way we program. Here are a
few of my favorites:
The MISSING function takes either a character or numeric argument and returns a value of True
if the argument is a missing value, and False otherwise. I no longer write statements such as
if Age = . then Age_group = .;
Instead, I write
if missing(Age) then Age_group = .;
or even,
if missing(Age) then call missing (Age_group);
Several others come to mind: The COMPRESS function with modifiers such as 'kd' is also one of
my favorites (take a look at some of the examples of this function in Chapter 1). The SAMEDAY
argument to the INTNX function adds huge functionality to this function (along with the new
25. xx
HOLIDAY function). I also recommend to all my students that they use the three FIND functions
(FIND, FINDC, and FINDW) instead of the older INDEX functions. I used to think the
concatenation functions were not all that useful; I have changed my mind about that. I use them
all the time.
I hope you find your personal favorites in this book.
Ron Cody
Winter, 2010
26. Preface to the First Edition
SAS functions provide some of the real power of SAS. This book covers almost two hundred of
the most common and useful functions and call routines—I did not attempt to describe every one.
Unlike SAS language manuals or other reference materials where SAS functions are merely
described, this book shows you the functions and one or more examples of how they can be used.
These examples are complete working programs. Sometimes the examples demonstrate a
common usage of the function; at other times, the use is non-traditional, but still very practical.
Some of the examples show how several functions can be used in combination to produce a
desired result.
This book contains useful information for veteran SAS users as well. For example, SAS now
supports Perl regular expressions. In addition, new arguments have been added to old functions
(such as COMPRESS and SCAN) that enhance their usefulness.
One of the strengths of SAS is its ability to manipulate character data. You will find extensive
examples of character manipulation in this book. For example, there are complete programs to
perform “fuzzy matching” using a combination of functions, including the SPEDIS (spelling
distance) function.
For those who are statistically inclined, there are examples of random number functions
performing Monte Carlo simulations, including the use of the SAS Output Delivery System
(ODS) to capture values from a procedure to a SAS data set.
I have decided to stay with the same function categories described in the latest version of the SAS
OnlineDoc. Because some of these functions have other important uses besides the obvious one
described by its category, I have provided two lists to allow you to look up a function by name,
and by program. There is also a traditional index that includes functions and tasks. Note: The
wording of arguments in this book might differ from the wording of arguments in the SAS
OnlineDoc.
Besides providing a nearly complete description of the Base SAS functions, I have provided
programs that I hope you will find useful in your daily programming tasks. Several of the more
useful examples here are also presented as SAS macros. All the programs in this book can be
downloaded from the author page for this book, located at support.sas.com/authors. The
programs can be used as is, or modified to fit your particular application.
27. xxii
By the way, this is the first book I have ever written while on sabbatical. In fact, this is the first
sabbatical I have ever had. I have truly enjoyed writing this book, even though I was “forced” to
embark on research trips to Virgin Gorda and Italy (a villa in the Chianti region). After several
bottles of excellent wine, I was able to conjure up some interesting examples to add to this book.
28. Acknowledgments
I don't suppose many folks read the Acknowledgments—and that is too bad. Although this book
has only one name on the cover, mine, it really takes a team to produce a book. To start with, I
had a team of reviewers, some from SAS, and others who are friends and colleagues not affiliated
with SAS. Some members of this team were responsible for only one or two chapters—others
read the book from cover to cover. Reviewing a book, and doing a good job of it, is a huge job.
I'm not sure why all these people volunteered to do this, but I am extremely grateful to them. As a
matter of fact, several of the reviewers have reviewed several of my books—and they keep
coming back for more! So, it is with sincere thanks that I acknowledge the following members of
my review team:
Mike Zdeb, Paul Grant, Jason Secosky, Kurt Jones, Scott McElroy, Charley Mullin,
Kathy Passarella, Kent Reeve, Russ Tyndall, and Sally Walczak
Next, no book project could go forward without a good editor, and I have a great one. John West
is amazing. He is always positive and makes my job so much easier. He is also assisted by many
other experts, namely:
Joel Byrd, copyeditor
Candy Farrell, technical publishing specialist
Shelly Goodin, marketing
Stacey Hamilton, marketing
Patrice Cherry, designer - front cover
Jennifer Dilley, designer - back cover
Mary Beth Steinbach, managing editor
Finally, as many fiction authors like to do, I would also like to acknowledge my wife's support in
my writing project. Thanks, Jan.
30. Introduction: A Brief Discussion of SAS
Functions and Call Routines
If you have written any SAS program, you probably used several functions and have an intuitive
idea of what functions do. SAS functions perform a computation or manipulation of a value and
return a single value. For example, the MONTH function computes the month of the year from a
SAS date; the ROUND function can round numeric values; the TODAY function returns the
current date.
SAS functions take the form of a function name, followed by a set of parentheses. In these
parentheses are usually one or more arguments. (Certain functions such as TODAY take no
arguments, but you need to follow the function name with an opening parenthesis and a closing
parenthesis anyway to tell SAS that you are referring to the TODAY function, not to a variable
called TODAY.) These arguments provide information that the function needs to return a result.
For example, the statement DAY_OF_WEEK = WEEKDAY(DATE); computes the day of the
week from a SAS date and assigns it to the variable DAY_OF_WEEK. This function, as with all
other SAS functions, returns a single value that is either assigned to a variable or used in a SAS
expression.
Finally, the arguments to most SAS functions can be variable names, constants (if a character
argument is needed, the constant must be in single or double quotation marks), or expressions
(that may also contain other functions).
CALL routines have some similarity to SAS functions because they often perform similar
operations. However, there are some important differences. CALL routines are not used in
assignment statements. Instead, they stand alone as SAS statements. Multiple arguments in a
CALL routine can be assigned new values by the routine. For example, the statement CALL
SCAN(string, n, position, length); returns the position and the length of the nth
"word" in the string. The SCAN function, on the other hand, returns only a single value—the nth
word in the string. Indeed, the main reason for using a CALL routine instead of a function is to
obtain more than one value in a single statement.
Functions and CALL routines in this book are arranged by category and topic. For example, in
Chapter 1, "Character Functions," there are topics such as "Functions That Search for Characters"
or "Functions That Remove Leading and Trailing Blanks from Strings." This author hopes that
this arrangement (as opposed to alphabetical order) will make it easier for you to find the function
you need quickly.
32. C h a p t e r 1
Character Functions
Introduction 3
Functions That Change the Case of Characters 5
UPCASE 6
LOWCASE 7
PROPCASE 9
Functions That Remove Characters from Strings 11
COMPBL 11
COMPRESS 12
Functions That Search for Characters 16
ANYALNUM 17 NOTLOWER 30
ANYALPHA 18 FIND 32
ANYDIGIT 19 FINDC 34
ANYPUNCT 20 FINDW 39
ANYSPACE 21 INDEX 42
ANYUPPER 22 INDEXC 42
ANYLOWER 23 VERIFY 44
NOTALNUM 26
NOTALPHA 27
NOTDIGIT 28
NOTUPPER 29
Functions That Extract Parts of Strings 46
SUBSTR 46
SUBSTRN 52
CHAR 54
FIRST 55
33. 2 SAS Functions by Example, Second Edition
Functions That Join Two or More Strings Together 57
CALL CATS 58 CATS 63
CALL CATT 59 CATT 64
CALL CATX 60 CATX 65
CAT 62 CATQ 66
Functions That Remove Blanks from Strings 70
LEFT 70 TRIMN 75
RIGHT 72 STRIP 77
TRIM 73
Functions That Compare Strings (Exact and "Fuzzy" Comparisons) 78
COMPARE 78 COMPLEV 84
CALL COMPCOST 81 SOUNDEX 89
COMPGED 82 SPEDIS 92
Functions That Divide Strings into "Words" 97
SCAN 97
CALL SCAN 102
Functions That Substitute Letters or Words in Strings 106
TRANSLATE 106
TRANWRD 109
Functions That Compute the Length of Strings 111
LENGTH 111
LENGTHC 112
LENGTHM 112
LENGTHN 113
Functions That Count the Number of Letters or Substrings in a String 114
COUNT 114
COUNTC 116
COUNTW 118
Miscellaneous String Functions 121
CHOOSEC 121
CHOOSEN 123
MISSING 125
COALESCEC 128
IFC 129
RANK 132
REPEAT 133
34. Chapter 1: Character Functions 3
REVERSE 135
NLITERAL 136
NVALID 138
Introduction
A major strength of SAS is its ability to work with character data. The SAS character
functions are essential to this. The collection of functions and CALL routines in this chapter
enable you to do extensive manipulation on all sorts of character data.
With the introduction of SAS®
9, the number of functions increased greatly (especially
character functions). In addition, many of the new character functions included arguments
that refer to character classes (such as all digits or all punctuation), making them even more
powerful.
After reading this chapter, you will also want to review the next chapter on Perl regular
expressions, another way to process character data.
Before delving into the realm of character functions, it is important to understand how SAS
stores character data and how the length of character variables gets assigned.
Storage Length for Character Variables
It is in the compile stage of the DATA step that SAS variables are determined to be character
or numeric, that the storage lengths of SAS character variables are determined, and that the
descriptor portion of the SAS data set is written. The following program will help you to
understand how character storage lengths are determined:
Program 1.1: How SAS determines storage lengths of character variables
data example1;
input Group $
@10 String $3.;
Left = 'x '; *x and 4 blanks;
Right = ' x'; *4 blanks and x;
Sub = substr(Group,1,2);
Rep = repeat(Group,1);
datalines;
ABCDEFGH 123
XXX 4
Y 5
;
35. 4 SAS Functions by Example, Second Edition
Explanation
The purpose of this program is not to demonstrate SAS character functions. That is why the
functions in this program are not printed in bold as they are in all the other programs in this
book. Let's look at each of the character variables created in this DATA step. To see the
storage length for each of the variables in data set EXAMPLE1, let's run PROC
CONTENTS. Here is the program:
Program 1.2: Running PROC CONTENTS to determine storage lengths
title "PROC CONTENTS for Data Set EXAMPLE1";
proc contents data=example1 varnum;
run;
The VARNUM option requests the variables to be in the order that they appear in the SAS
data set, rather than the default, alphabetical order. The output is shown next:
Variables in Creation Order
# Variable Type Len
1 Group Char 8
2 String Char 3
3 Left Char 5
4 Right Char 5
5 Sub Char 8
6 Rep Char 200
First, GROUP is read using list input. No informat is used, so SAS will give the variable the
default length of 8. Since STRING is read with an informat, the length is set to the informat
width of 3. LEFT and RIGHT are both created with an assignment statement. Therefore the
length of these two variables is equal to the number of characters between the quotes. In this
program, single quotes are used to create LEFT and RIGHT. The program would produce
the same result if double quotes were used. In most cases, you can use either single or double
quotes to create a character constant. Note that if a variable appears several times in a DATA
step, its length is determined by the first reference to that variable.
For example, beginning SAS programmers often get in trouble with statements such as:
if Sex = 1 then Gender = 'Male';
else if Sex = 2 then Gender = 'Female';
36. Chapter 1: Character Functions 5
The length of GENDER in the two previous lines is 4, since the statement in which the
variable first appears defines its length.
There are several ways to make sure a character variable is assigned the proper length.
Probably the best way is to use a LENGTH statement. So, if you precede the two previous
lines with the statement:
length Gender $ 6;
the length of GENDER will be 6, not 4. Some lazy programmers will "cheat" by adding two
blanks after MALE in the assignment statement (me, never!). Another trick is to place the
line for FEMALE first.
So, continuing on to the last two variables. You see a length of 8 for the variable SUB. As
you will see later in this chapter, the SUBSTR (substring) function can extract some or all of
one string and assign the result to a new variable. Since SAS has to determine variable
lengths in the compile stage and since the SUBSTR arguments that define the starting point
and the length of the substring could possibly be determined in the execution stage (from
data values, for example), SAS does the logical thing: it gives the variable defined by the
SUBSTR function the longest length it could possibly need—the length of the string from
which you are taking the substring.
Finally, the variable REP is created by using the REPEAT function. As you will find out
later in this chapter, the REPEAT function takes a string and repeats it as many times as
directed by the second argument to the function. Using the same logic as the SUBSTR
function, since the length of REP is determined in the compile stage and since the number of
repetitions could vary, SAS gives it a default length of 200. A note of historical interest:
Prior to SAS 7, the maximum length of character variables was 200. With the coming of
SAS 7, the maximum length of character variables was increased to 32,767. SAS made a
very wise decision to leave the default length at 200 for situations such as the REPEAT
function described here. The take-home message is that you should always be sure that you
know the storage lengths of your character variables.
Functions That Change the Case of Characters
Two old functions, UPCASE and LOWCASE, change the case of characters. As of SAS®
9,
a new function, PROPCASE (proper case), capitalizes the first letter of each word.
37. 6 SAS Functions by Example, Second Edition
Function: UPCASE
Purpose: To change all letters to uppercase.
Note: The corresponding function LOWCASE changes uppercase to
lowercase.
Syntax: UPCASE(character-value)
character-value is any SAS character value.
If a length has not been previously assigned, the length of the resulting
variable will be the length of the argument.
Examples
For these examples, CHAR = "ABCxyz".
Function Returns
UPCASE(CHAR) "ABCXYZ"
UPCASE("a1%m?") "A1%M?"
Program 1.3: Changing lowercase to uppercase for all character variables
in a data set
***Primary function: UPCASE
***Other function: DIM;
data mixed;
length a b c d e $ 1;
input a b c d e x y;
datalines;
M f P p D 1 2
m f m F M 3 4
;
data upper;
set mixed;
array all_c[*] _character_;
do i = 1 to dim(all_c);
all_c[i] = upcase(all_c[i]);
end;
drop i;
run;
38. Chapter 1: Character Functions 7
title 'Listing of Data Set UPPER';
proc print data=upper noobs;
run;
Explanation
Remember that uppercase and lowercase values are represented by different internal codes,
so if you are testing for a value such as Y for a variable and the actual value is y, you will
not get a match. Therefore, it is often useful to convert all character values to either
uppercase or lowercase before doing your logical comparisons. In this program,
_CHARACTER_ is used in the array statement to represent all the character variables in the
data set MIXED. Inspection of the following listing verifies that all lowercase values were
changed to uppercase.
Listing of Data Set UPPER
a b c d e x y
M F P P D 1 2
M F M F M 3 4
Function: LOWCASE
Purpose: To change all letters to lowercase.
Syntax: LOWCASE(character-value)
character-value is any SAS character value.
Note: The corresponding function UPCASE changes lowercase to
uppercase.
If a length has not been previously assigned, the length of the resulting
variable will be the length of the argument.
Examples
For these examples, CHAR = "ABCxyz".
Function Returns
LOWCASE(CHAR) "abcxyz"
LOWCASE("A1%M?") "a1%m?"
39. 8 SAS Functions by Example, Second Edition
Program 1.4: Program to demonstrate the LOWCASE function
***Primary function: LOWCASE;
data wt;
Input ID : $3. Unit : $1. Weight;
Unit = lowcase(Unit);
if Unit eq 'k' then Wt_lbs = 2.2*Weight;
else if Unit = 'l' then Wt_lbs = Weight;
datalines;
001 k 100
002 K 101
003 L 201
004 l 166
;
title "Listing of Data Set WT";
proc print data=wt noobs;
run;
Explanation
This program demonstrates a common problem—dealing with character data in mixed case.
Here you see that the values of the variable Unit are sometimes in uppercase and sometimes
in lowercase. A simple way to solve this problem is to use the LOWCASE function to ensure
that all values of Unit will be in lowercase.
You could also have used the UPCASE function to convert all the Unit values to uppercase.
Note: If you have mixed case data, you can use the $UPCASE informat to convert the values
to uppercase as they are being read. There is no corresponding $LOWCASE informat.
The remainder of the program is straightforward: after you convert all the values of Unit to
lowercase, you only have to check for lowercase k's and l's to determine whether you need to
multiply the Weight value by 2.2 or not. The following listing shows that this program
worked as desired (the variables Unit and Weight would normally be dropped in a program
like this):
Listing of Data Set WT
ID Unit Weight Wt_lbs
001 k 100 220.0
002 k 101 222.2
003 l 201 201.0
004 l 166 166.0
40. Chapter 1: Character Functions 9
Function: PROPCASE
Purpose: To capitalize the first letter of each word in a string.
Syntax: PROPCASE(character-value <,delimiters>)
character-value is any SAS character value.
Delimiters An optional list of word delimiters. The default delimiters
are blank, forward slash, hyphen, open parenthesis, period, and tab.
If a length has not been previously assigned, the length of the resulting
variable will be the length of the argument.
Examples
For these examples, CHAR = "ABCxyz".
Function Returns
PROPCASE(CHAR) "Abcxyz"
PROPCASE("a1%m?") "A1%m?"
PROPCASE("mr. george w. bush") "Mr. George W. Bush"
PROPCASE("l'oeuf") "L'oeuf" ("the egg" in French)
PROPCASE("l'oeuf","' ") "L'Oeuf"
Note: It seems useful to use both blanks and single quotes as delimiters since you
would like names such as D'Allesandro to have an uppercase letter following the
single quote.
Program 1.5: Capitalizing the first letter of each word in a string
***Primary function: PROPCASE;
data proper;
input Name $60.;
Name = propcase(Name);
datalines;
ronald cODy
THomaS eDISON
albert einstein
;
41. 10 SAS Functions by Example, Second Edition
title "Listing of Data Set PROPER";
proc print data=proper noobs;
run;
Explanation
In this program, you use the PROPCASE function to capitalize the first letter of the first and
last names. Here is the listing:
Listing of Data Set PROPER
Name
Ronald Cody
Thomas Edison
Albert Einstein
Program 1.6: Program to capitalize the first letter of each word in a string
***First and last name are two separate variables;
data proper;
informat First Last $30.;
input First Last;
length Name $ 60;
Name = catx(' ', First, Last);
Name = propcase(Name);
datalines;
ronald cODy
THomaS eDISON
albert einstein
;
title "Listing of Data Set PROPER";
proc print data=proper noobs;
run;
Explanation
In this program, the first and last names are stored in separate variables and you want a new
variable (NAME) that contains both first and last name (in proper case).
The CATX function is used to concatenate the first and last name with a blank as the
separator character. The PROPCASE function is then used to capitalize each name. The
listing is identical to the preceding listing.
42. Chapter 1: Character Functions 11
Functions That Remove Characters from Strings
COMPBL (compress blanks) can replace multiple blanks with a single blank. The
COMPRESS function can remove not only blanks, but also any characters you specify from
a string.
Function: COMPBL
Purpose: To replace all occurrences of two or more blanks with a single blank
character. This is particularly useful for standardizing addresses and names
where multiple blanks may have been entered.
Syntax: COMPBL(character-value)
character-value is any SAS character value.
If a length has not been previously assigned, the length of the resulting
variable will be the length of the argument.
Example
For these examples, CHAR = "A C XYZ".
Function Returns
COMPBL(CHAR) "A C XYZ"
COMPBL("X Y Z LAST") "X Y Z LAST"
Program 1.7: Using the COMPBL function to convert multiple blanks to a
single blank
***Primary function: COMPBL;
data squeeze;
input #1 @1 Name $20.
#2 @1 Address $30.
#3 @1 City $15.
@20 State $2.
@25 Zip $5.;
Name = compbl(Name);
Address = compbl(Address);
City = compbl(City);
datalines;
Ron Cody
43. 12 SAS Functions by Example, Second Edition
89 Lazy Brook Road
Flemington NJ 08822
Bill Brown
28 Cathy Street
North City NY 11518
;
title 'Listing of Data Set SQUEEZE';
proc print data=squeeze;
id Name;
var Address City State Zip;
run;
Explanation
Each line of the address was passed through the COMPBL function to replace any sequence
of two or more blanks to a single blank. Here is a listing of data set SQUEEZE:
Listing of Data Set SQUEEZE
Name Address City State Zip
Ron Cody 89 Lazy Brook Road Flemington NJ 08822
Bill Brown 28 Cathy Street North City NY 11518
Function: COMPRESS
Purpose: To remove specified characters from a character value. When used with the
k modifier, compress can be used to keep characters (such as digits) in a
character value and remove everything else.
Syntax: COMPRESS(character-value <,'compress-list'>
<,'modifiers'>)
character-value is any SAS character value.
compress-list is an optional list of the characters you want to remove.
If this argument is omitted, the default character to be removed is a blank. If
you include a list of characters to remove, only those characters will be
removed (unless the 'k' modifier is used). If a blank is not included in the
list, blanks will not be removed.
modifiers is an optional list of modifiers that refer to character classes.
For example, the a modifier refers to all uppercase and lowercase
characters. The following are some of the more useful modifiers:
44. Chapter 1: Character Functions 13
a include all uppercase and lowercase letters.
d include all digits.
s include all space characters (blanks, horizontal and vertical
tabs, carriage return, linefeed, and formfeed).
i ignore the case of characters.
k keep the characters listed in the compress-list or
referenced by the modifiers instead of removing them.
p include all punctuation characters.
Note that the modifiers can be in uppercase or lowercase.
If a length has not been previously assigned, the length of the resulting
variable will be the length of the first argument.
Examples
In the following examples, CHAR = "A C123XYZ".
Function Returns
COMPRESS("A C XYZ") "ACXYZ"
COMPRESS("(908) 777-1234"," (-)") "9087771234"
COMPRESS(CHAR,,'as') "123"
COMPRESS(CHAR,"0123456789") "A CXYZ"
COMPRESS(CHAR,,'d') "A CXYZ"
COMPRESS(CHAR,"ABC",'d') " XYZ"
COMPRESS(CHAR,,'kd') "123"
Program 1.8: Removing dashes and parentheses from phone numbers
***Primary function: COMPRESS;
data phone_number;
input Phone $ 1-15;
Phone1 = compress(Phone);
Phone2 = compress(Phone,'(-) ');
Phone3 = compress(Phone,,'kd');
datalines;
(908)235-4490
(201) 555-77 99
;
45. 14 SAS Functions by Example, Second Edition
title 'Listing of Data Set PHONE_NUMBER';
proc print data=phone_number;
run;
Explanation
For the variable PHONE1, the second argument is omitted from the COMPRESS function;
therefore, only blanks are removed. For PHONE2, left and right parentheses, dashes, and
blanks are listed in the second argument, so all of these characters are removed from the
character value. Finally, for PHONE3, the two modifiers k (keep) and d (digits) are used to
keep all the digits in the PHONE value and remove everything else. Note that there are two
commas following the first argument. If you used only one comma here, SAS would think
you wanted to remove k's and d's from the PHONE value. Even though the results for
PHONE2 and PHONE3 are identical, it is usually better to specify what you want to keep
rather than what you want to remove. Why? Suppose your original PHONE value contained
some unwanted character such as a punctuation mark or even a non-printing character. Using
the k and d modifiers ensures that you wind up with only digits in the result.
The following listing shows the output:
Listing of Data Set PHONE_NUMBER
Obs Phone Phone1 Phone2 Phone3
1 (908)235-4490 (908)235-4490 9082354490 9082354490
2 (201) 555-77 99 (201)555-7799 2015557799 2015557799
Converting Social Security Numbers to Numeric Form
Here is another example where the COMPRESS function makes it easy to convert a standard
Social Security number, including the dashes, to a numeric value.
Program 1.9: Converting Social Security numbers from character to
numeric
***Primary function: COMPRESS
***Other function: INPUT;
data social;
input @1 SS_char $11.
@1 Mike_Zdeb comma11.;
SS_numeric = input(compress(SS_char,'-'),9.);
SS_formatted = SS_numeric;
format SS_formatted ssn.;
46. Chapter 1: Character Functions 15
datalines;
123-45-6789
001-11-1111
;
title "Listing of Data Set SOCIAL";
proc print data=social noobs;
run;
Explanation
The COMPRESS function is used to remove the dashes from the Social Security number and
the INPUT function does the character-to-numeric conversion.
It should be noted here that the Social Security number, including dashes, can be read
directly into a numeric variable using the comma11. informat. This trick was brought to light
by Mike Zdeb in a NESUG workshop in Buffalo in the Fall of 2002. Here, the variable
SS_FORMATTED is set equal to the variable SS_NUMERIC so that you can see the effect
of adding the SSN. format. (Note that SSN. is equivalent to SSN11.) This format prints
numeric values with leading zeros and dashes in the proper places, as you can see in the
following listing:
Listing of Data Set SOCIAL
SS_char Mike_Zdeb SS_numeric SS_formatted
123-45-6789 123456789 123456789 123-45-6789
001-11-1111 1111111 1111111 001-11-1111
Counting the Number of Digits in a Character String
This program computes the number of digits in a string by a novel method. It uses the
COMPRESS function to remove all digits from the string and then subtracts the resulting
length from the original length for the computation.
Program 1.10: Counting the number of digits in a string
***Primary functions: COMPRESS, LENGTHN;
data count;
input String $20.;
Only_letters = compress(String,,'d');
Num_numerals = lengthn(String) - lengthn(Only_letters);
datalines;
ABC123XYZ
47. 16 SAS Functions by Example, Second Edition
XXXXX
12345
1234X
;
title "Listing of Data Set COUNT";
proc print data=count noobs;
run;
Explanation
This is an interesting application of the COMPRESS function. By computing the length of
the string before and after removing the digits, this program sets the difference in the lengths
to the number of digits in the original string. Notice the use of the LENGTHN function
instead of the LENGTH function. When the COMPRESS function operates on the third
observation (all digits), the result is a null string. The LENGTH function returns a value of 1
in this situation; the LENGTHN function returns a value of 0. See LENGTH and LENGTHN
function descriptions for a detailed explanation.
Listing of Data Set COUNT
Only_ Num_
String letters numerals
ABC123XYZ ABCXYZ 3
XXXXX XXXXX 0
12345 5
1234X X 4
Functions That Search for Characters
Functions in this category enable you to search a string for specific characters or for a
character category (such as a digit). Some of these functions can also locate the first position
in a string where a character does not meet a particular specification. Quite a few of the
functions in this section were added with SAS®
9, and they provide some new and useful
capabilities.
The "ANY" Functions (ANYALNUM, ANYALPHA, ANYDIGIT,
ANYPUNCT, ANYSPACE, ANYUPPER, and ANYLOWER)
This group of functions is described together because of the similarity of their use. These
functions return the location of the first alphanumeric, letter, digit, etc. in a character value.
Note that there are other "ANY" functions besides those presented here; these are the most
48. Chapter 1: Character Functions 17
common ones (for a complete list, see Product Documentation in the Knowledge Base,
available at http://support.sas.com/documentation).
It is important to note that it might be necessary to use the TRIM function (or STRIP
function) with the "ANY" and, especially, the "NOT" functions, since leading or trailing
blanks might affect the results. For example, if X = "ABC " (ABC followed by three
blanks), Y = NOTALPHA(X) (return the location of the first character in X that is not a
letter) will be 4, the location of the first trailing blank. Therefore, you might want to
routinely use TRIM (or STRIP) like this:
Y = NOTALPHA(TRIM(X));
Note that there is a group of similar functions (NOTALPHA, NOTDIGIT, etc.) that work in
a similar manner and are described together later in the next section. One program example
follows the description of these seven functions.
Function: ANYALNUM
Purpose: To locate the first occurrence of an alphanumeric character (any uppercase
or lowercase letter or number) and return its position. If none is found, the
function returns a 0. With the use of an optional parameter, this function can
begin searching at any position in the string and can also search from right
to left, if desired.
Syntax: ANYALNUM(character-value <,start>)
character-value is any SAS character value.
start is an optional parameter that specifies the position in the string to
begin the search. If it is omitted, the search starts at the beginning of the
string. If it is non-zero, the search begins at the position in the string of the
absolute value of the number (starting from the left-most position in the
string). If the start value is positive, the search goes from left to right; if the
value is negative, the search goes from right to left. A negative value larger
than the length of the string results in a scan from right to left, starting at the
end of the string. If the value of start is a positive number longer than the
length of the string, or if it is 0, the function returns a 0.
49. 18 SAS Functions by Example, Second Edition
Examples
For these examples, STRING = "ABC 123 ?xyz_n_".
Function Returns
ANYALNUM(STRING) 1 (position of "A")
ANYALNUM("??$$%%") 0 (no alpha-numeric characters)
ANYALNUM(STRING,5) 5 (position of "1")
ANYALNUM(STRING,-4) 3 (position of "C")
ANYALNUM(STRING,6) 6 (position of "2")
Function: ANYALPHA
Purpose: To locate the first occurrence of an alpha character (any uppercase or
lowercase letter) and return its position. If none is found, the function
returns a 0. With the use of an optional parameter, this function can begin
searching at any position in the string and can also search from right to left,
if desired.
Syntax: ANYALPHA(character-value <,start>)
character-value is any SAS character value.
start is an optional parameter that specifies the position in the string to
begin the search. If it is omitted, the search starts at the beginning of the
string. If it is non-zero, the search begins at the position in the string of the
absolute value of the number (starting from the left-most position in the
string). If the start value is positive, the search goes from left to right; if the
value is negative, the search goes from right to left. A negative value larger
than the length of the string results in a scan from right to left, starting at the
end of the string. If the value of start is a positive number longer than the
length of the string, or if it is 0, the function returns a 0.
Examples
For these examples, STRING = "ABC 123 ?xyz_n_".
50. Chapter 1: Character Functions 19
Function Returns
ANYALPHA(STRING) 1 (position of "A")
ANYALPHA("??$$%%") 0 (no alpha characters)
ANYALPHA(STRING,5) 10 (position of "x")
ANYALPHA(STRING,-4) 3 (position of "C")
ANYALPHA(STRING,6) 10 (position of "x")
Function: ANYDIGIT
Purpose: To locate the first occurrence of a digit (numeral) and return its position. If
none is found, the function returns a 0. With the use of an optional
parameter, this function can begin searching at any position in the string and
can also search from right to left, if desired.
Syntax: ANYDIGIT(character-value <,start>)
character-value is any SAS character value.
start is an optional parameter that specifies the position in the string to
begin the search. If it is omitted, the search starts at the beginning of the
string. If it is non-zero, the search begins at the position in the string of the
absolute value of the number (starting from the left-most position in the
string). If the start value is positive, the search goes from left to right; if the
value is negative, the search goes from right to left. A negative value larger
than the length of the string results in a scan from right to left, starting at the
end of the string. If the value of start is a positive number longer than the
length of the string, or if it is 0, the function returns a 0.
Examples
For these examples, STRING = "ABC 123 ?xyz_n_".
51. 20 SAS Functions by Example, Second Edition
Function Returns
ANYDIGIT(STRING) 5 (position of "1")
ANYDIGIT("??$$%%") 0 (no digits)
ANYDIGIT(STRING,5) 5 (position of "1")
ANYDIGIT(STRING,-4) 0 (no digits from position 4 to 1)
ANYDIGIT(STRING,6) 6 (position of "2")
Function: ANYPUNCT
Purpose: To locate the first occurrence of a punctuation character and return its
position. If none is found, the function returns a 0. With the use of an
optional parameter, this function can begin searching at any position in the
string and can also search from right to left, if desired.
In the ASCII character set, the following characters are considered
punctuation:
! " # $ % & ' ( ) * + , - . / : ;
< = > ? @ [ ] ^ _ ` { | } ~
Syntax: ANYPUNCT(character-value <,start>)
character-value is any SAS character value.
start is an optional parameter that specifies the position in the string to
begin the search. If it is omitted, the search starts at the beginning of the
string. If it is non-zero, the search begins at the position in the string of the
absolute value of the number (starting from the left-most position in the
string). If the start value is positive, the search goes from left to right; if the
value is negative, the search goes from right to left. A negative value larger
than the length of the string results in a scan from right to left, starting at the
end of the string. If the value of start is a positive number longer than the
length of the string, or if it is 0, the function returns a 0.
Examples
For these examples, STRING = "A!C 123 ?xyz_n_".
52. Chapter 1: Character Functions 21
Function Returns
ANYPUNCT(STRING) 2 (position of "!")
ANYPUNCT("??$$%%") 1 (position of "?")
ANYPUNCT(STRING,5) 9 (position of "?")
ANYPUNCT(STRING,-4) 2 (starts at position 4 and goes left, position of "!")
ANYPUNCT(STRING,-3) 2 (starts at position 3 and goes left, position of "!")
Function: ANYSPACE
Purpose: To locate the first occurrence of a white space character (a blank, horizontal
or vertical tab, carriage return, linefeed, and form-feed) and return its
position. If none is found, the function returns a 0. With the use of an
optional parameter, this function can begin searching at any position in the
string and can also search from right to left, if desired.
Syntax: ANYSPACE(character-value <,start>)
character-value is any SAS character value.
start is an optional parameter that specifies the position in the string to
begin the search. If it is omitted, the search starts at the beginning of the
string. If it is non-zero, the search begins at the position in the string of the
absolute value of the number (starting from the left-most position in the
string). If the start value is positive, the search goes from left to right; if the
value is negative, the search goes from right to left. A negative value larger
than the length of the string results in a scan from right to left, starting at the
end of the string. If the value of start is a positive number longer than the
length of the string, or if it is 0, the function returns a 0.
Examples
For these examples, STRING = "ABC 123 ?xyz_n_".
53. 22 SAS Functions by Example, Second Edition
Function Returns
ANYSPACE(STRING) 4 (position of the first blank)
ANYSPACE("??$$%%") 0 (no spaces)
ANYSPACE(STRING,5) 8 (position of the second blank)
ANYSPACE(STRING,-4) 4 (position of the first blank)
Function: ANYUPPER
Purpose: To locate the first occurrence of an uppercase letter and return its position. If
none is found, the function returns a 0. With the use of an optional
parameter, this function can begin searching at any position in the string and
can also search from right to left, if desired.
Syntax: ANYUPPER(character-value <,start>)
character-value is any SAS character value.
start is an optional parameter that specifies the position in the string to
begin the search. If it is omitted, the search starts at the beginning of the
string. If it is non-zero, the search begins at the position in the string of the
absolute value of the number (starting from the left-most position in the
string). If the start value is positive, the search goes from left to right; if the
value is negative, the search goes from right to left. A negative value larger
than the length of the string results in a scan from right to left, starting at the
end of the string. If the value of start is a positive number longer than the
length of the string, or if it is 0, the function returns a 0.
Examples
For these examples, STRING = "abcABC123".
Function Returns
ANYUPPER(STRING) 4 (position of "A")
ANYUPPER("abc123") 0 (no uppercase characters)
ANYUPPER(STRING,5) 5 (position of "B")
ANYUPPER(STRING,-9) 6 (position of "C")
54. Chapter 1: Character Functions 23
Function: ANYLOWER
Purpose: To locate the first occurrence of a lowercase letter and return its position. If
none is found, the function returns a 0. With the use of an optional
parameter, this function can begin searching at any position in the string and
can also search from right to left, if desired.
Syntax: ANYLOWER(character-value <,start>)
character-value is any SAS character value.
start is an optional parameter that specifies the position in the string to
begin the search. If it is omitted, the search starts at the beginning of the
string. If it is non-zero, the search begins at the position in the string of the
absolute value of the number (starting from the left-most position in the
string). If the start value is positive, the search goes from left to right; if the
value is negative, the search goes from right to left. A negative value larger
than the length of the string results in a scan from right to left, starting at the
end of the string. If the value of start is a positive number longer than the
length of the string, or if it is 0, the function returns a 0.
Examples
For these examples, STRING = "abcABC123".
Function Returns
ANYLOWER(STRING) 1 (position of "a")
ANYLOWER("ABC123") 0 (no lowercase characters)
ANYLOWER(STRING,3) 3 (position of "c")
ANYLOWER(STRING,-9) 3 (position of "c")
59. The Project Gutenberg eBook of Encyclopaedia
Britannica, 11th Edition, "Matter" to
"Mecklenburg"
60. This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Title: Encyclopaedia Britannica, 11th Edition, "Matter" to
"Mecklenburg"
Author: Various
Release date: April 7, 2013 [eBook #42473]
Most recently updated: October 23, 2024
Language: English
Credits: Produced by Marius Masi, Don Kretz and the Online
Distributed Proofreading Team at http://www.pgdp.net
*** START OF THE PROJECT GUTENBERG EBOOK ENCYCLOPAEDIA
BRITANNICA, 11TH EDITION, "MATTER" TO "MECKLENBURG" ***
61. Transcriber’s note: A few typographical errors have been
corrected. They appear in the text like this,
and the explanation will appear when the
mouse pointer is moved over the marked
passage. Sections in Greek will yield a
transliteration when the pointer is moved
over them, and words using diacritic
characters in the Latin Extended Additional
block, which may not display in some fonts
or browsers, will display an unaccented
version.
Links to other EB articles: Links to articles
residing in other EB volumes will be made
available when the respective volumes are
introduced online.
63. A DICTIONARY OF ARTS, SCIENCES,
LITERATURE AND GENERAL
INFORMATION
ELEVENTH EDITION
VOLUME XVII SLICE VIII
Matter to Mecklenburg
Articles in This Slice
MATTER MAX MÜLLER, FRIEDRICH
MATTERHORN MAXWELL
MATTEUCCI, CARLO MAXWELL, JAMES CLERK
MATTHEW, ST MAXWELLTOWN
64. MATTHEW, TOBIAS MAY, PHIL
MATTHEW, GOSPEL OF ST MAY, THOMAS
MATTHEW CANTACUZENUS MAY, WILLIAM
MATTHEW OF PARIS MAY (month)
MATTHEW OF WESTMINSTER MAY, ISLE OF
MATTHEWS, STANLEY MAYA
MATTHIAE, AUGUST HEINRICH MAYAGUEZ
MATTHIAS (disciple) MAYAVARAM
MATTHIAS (Roman emperor) MAYBOLE
MATTHIAS I., HUNYADI MAYEN
MATTHISSON, FRIEDRICH VON MAYENNE, CHARLES OF
LORRAINE
MATTING MAYENNE (department of
France)
MATTOCK MAYENNE (town of France)
MATTO GROSSO MAYER, JOHANN TOBIAS
MATTOON MAYER, JULIUS ROBERT
MATTRESS MAYFLOWER
MATURIN, CHARLES ROBERT MAY-FLY
MATVYEEV, ARTAMON
SERGYEEVICH
MAYHEM
MAUBEUGE MAYHEW, HENRY
MAUCH CHUNK MAYHEW, JONATHAN
MAUCHLINE MAYHEW, THOMAS
MAUDE, CYRIL MAYMYO
MAULE MAYNARD, FRANÇOIS DE
MAULÉON, SAVARI DE MAYNE, JASPER
MAULSTICK MAYNOOTH
MAUNDY THURSDAY MAYO, RICHARD SOUTHWELL
BOURKE
65. MAUPASSANT, HENRI RENÉ
ALBERT GUY DE
MAYO
MAUPEOU, RENÉ NICOLAS
CHARLES AUGUSTIN
MAYOR, JOHN EYTON
BICKERSTETH
MAUPERTUIS, PIERRE LOUIS
MOREAU DE
MAYOR
MAU RANIPUR MAYOR OF THE PALACE
MAUREL, ABDIAS MAYORUNA
MAUREL, VICTOR MAYO-SMITH, RICHMOND
MAURENBRECHER, KARL PETER
WILHELM
MAYOTTE
MAUREPAS, JEAN FRÉDÉRIC
PHÉLYPEAUX
MAYOW, JOHN
MAURER, GEORG LUDWIG VON MAYSVILLE
MAURETANIA MAZAGAN
MAURIAC MAZAMET
MAURICE, ST MAZANDARAN
MAURICE (Roman emperor) MAZARIN, JULES
MAURICE (elector of Saxony) MAZAR-I-SHARIF
MAURICE, JOHN FREDERICK
DENISON
MAZARRÓN
MAURICE OF NASSAU MAZATLÁN
MAURISTS MAZE
MAURITIUS MAZEPA-KOLEDINSKY, IVAN
STEPANOVICH
MAURY, JEAN SIFFREIN MAZER
MAURY, LOUIS FERDINAND
ALFRED
MAZURKA
MAURY, MATTHEW FONTAINE MAZZARA DEL VALLO
MAUSOLEUM MAZZINI, GIUSEPPE
MAUSOLUS MAZZONI, GIACOMO
66. MAUVE, ANTON MAZZONI, GUIDO
MAVROCORDATO MEAD, LARKIN GOLDSMITH
MAWKMAI MEAD, RICHARD
MAXENTIUS, MARCUS AURELIUS
VALERIUS
MEAD
MAXIM, SIR HIRAM STEVENS MEADE, GEORGE GORDON
MAXIMA AND MINIMA MEADE, WILLIAM
MAXIMIANUS MEADVILLE
MAXIMIANUS, MARCUS AURELIUS
VALERIUS
MEAGHER, THOMAS FRANCIS
MAXIMILIAN I. (elector of Bavaria) MEAL
MAXIMILIAN I. (king of Bavaria) MEALIE
MAXIMILIAN II. (king of Bavaria) MEAN
MAXIMILIAN I. (Roman emperor) MEASLES
MAXIMILIAN II. (Roman emperor) MEAT
MAXIMILIAN (emperor of Mexico) MEATH
MAXIMINUS, GAIUS JULIUS
VERUS
MEAUX
MAXIMINUS, GALERIUS VALERIUS MECCA
MAXIMS, LEGAL MECHANICS
MAXIMUS MECHANICVILLE
MAXIMUS, ST MECHITHARISTS
MAXIMUS OF SMYRNA MECKLENBURG
MAXIMUS OF TYRE
67. MATTER. Our conceptions of the nature and structure of
matter have been profoundly influenced in recent years by
investigations on the Conduction of Electricity through Gases (see
Conduction, Electric) and on Radio-activity (q.v.). These researches
and the ideas which they have suggested have already thrown much
light on some of the most fundamental questions connected with
matter; they have, too, furnished us with far more powerful methods
for investigating many problems connected with the structure of
matter than those hitherto available. There is thus every reason to
believe that our knowledge of the structure of matter will soon
become far more precise and complete than it is at present, for now
we have the means of settling by testing directly many points which
are still doubtful, but which formerly seemed far beyond the reach of
experiment.
The Molecular Theory of Matter—the only theory ever seriously
advocated—supposes that all visible forms of matter are collocations
of simpler and smaller portions. There has been a continuous
tendency as science has advanced to reduce further and further the
number of the different kinds of things of which all matter is
supposed to be built up. First came the molecular theory teaching us
to regard matter as made up of an enormous number of small
particles, each kind of matter having its characteristic particle, thus
the particles of water were supposed to be different from those of
68. air and indeed from those of any other substance. Then came
Dalton’s Atomic Theory which taught that these molecules, in spite
of their almost infinite variety, were all built up of still smaller bodies,
the atoms of the chemical elements, and that the number of
different types of these smaller bodies was limited to the sixty or
seventy types which represent the atoms of the substance regarded
by chemists as elements.
In 1815 Prout suggested that the atoms of the heavier chemical
elements were themselves composite and that they were all built up
of atoms of the lightest element, hydrogen, so that all the different
forms of matter are edifices built of the same material—the atom of
hydrogen. If the atoms of hydrogen do not alter in weight when they
combine to form atoms of other elements the atomic weights of all
elements would be multiples of that of hydrogen; though the
number of elements whose atomic weights are multiples or very
nearly so of hydrogen is very striking, there are several which are
universally admitted to have atomic weights differing largely from
whole numbers. We do not know enough about gravity to say
whether this is due to the change of weight of the hydrogen atoms
when they combine to form other atoms, or whether the primordial
form from which all matter is built up is something other than the
hydrogen atom. Whatever may be the nature of this primordial form,
the tendency of all recent discoveries has been to emphasize the
truth of the conception of a common basis of matter of all kinds.
That the atoms of the different elements have a common basis, that
they behave as if they consisted of different numbers of small
particles of the same kind, is proved to most minds by the Periodic
Law of Mendeléeff and Newlands (see Element). This law shows that
the physical and chemical properties of the different elements are
determined by their atomic weights, or to use the language of
69. mathematics, the properties of an element are functions of its
atomic weight. Now if we constructed models of the atoms out of
different materials, the atomic weight would be but one factor out of
many which would influence the physical and chemical properties of
the model, we should require to know more than the atomic weight
to fix its behaviour. If we were to plot a curve representing the
variation of some property of the substance with the atomic weight
we should not expect the curve to be a smooth one, for instance two
atoms might have the same atomic weight and yet if they were
made of different materials have no other property in common. The
influence of the atomic weight on the properties of the elements is
nowhere more strikingly shown than in the recent developments of
physics connected with the discharge of electricity through gases
and with radio-activity. The transparency of bodies to Röntgen rays,
to cathode rays, to the rays emitted by radio-active substances, the
quality of the secondary radiation emitted by the different elements
are all determined by the atomic weight of the element. So much is
this the case that the behaviour of the element with respect to these
rays has been used to determine its atomic weight, when as in the
case of Indium, uncertainty as to the valency of the element makes
the result of ordinary chemical methods ambiguous.
The radio-active elements indeed furnish us with direct evidence
of this unity of composition of matter, for not only does one element
uranium, produce another, radium, but all the radio-active
substances give rise to helium, so that the substance of the atoms of
this gas must be contained in the atoms of the radio-active
elements.
It is not radio-active atoms alone that contain a common
constituent, for it has been found that all bodies can by suitable
70. treatment, such as raising them to incandescence or exposing them
to ultra-violet light, be made to emit negatively electrified particles,
and that these particles are the same from whatever source they
may be derived. These particles all carry the same charge of
negative electricity and all have the same mass, this mass is
exceedingly small even when compared with the mass of an atom of
hydrogen, which until the discovery of these particles was the
smallest mass known to science. These particles are called
corpuscles or electrons; their mass according to the most recent
determinations is only about 1⁄1700 of that of an atom of hydrogen,
and their radius is only about one hundred-thousandth part of the
radius of the hydrogen atom. As corpuscles of this kind can be
obtained from all substances, we infer that they form a constituent
of the atoms of all bodies. The atoms of the different elements do
not all contain the same number of corpuscles—there are more
corpuscles in the atoms of the heavier elements than in the atoms of
the lighter ones; in fact, many different considerations point to the
conclusion that the number of corpuscles in the atom of any element
is proportional to the atomic weight of the element. Different
methods of estimating the exact number of corpuscles in the atom
have all led to the conclusion that this number is of the same order
as the atomic weight; that, for instance, the number of corpuscles in
the atom of oxygen is not a large multiple of 16. Some methods
indicate that the number of corpuscles in the atom is equal to the
atomic weight, while the maximum value obtained by any method is
only about four times the atomic weight. This is one of the points on
which further experiments will enable us to speak with greater
precision. Thus one of the constituents of all atoms is the negatively
charged corpuscle; since the atoms are electrically neutral, this
negative charge must be accompanied by an equal positive one, so
71. that on this view the atoms must contain a charge of positive
electricity proportional to the atomic weight; the way in which this
positive electricity is arranged is a matter of great importance in the
consideration of the constitution of matter. The question naturally
arises, is the positive electricity done up into definite units like the
negative, or does it merely indicate a property acquired by an atom
when one or more corpuscles leave it? It is very remarkable that we
have up to the present (1910), in spite of many investigations on
this point, no direct evidence of the existence of positively charged
particles with a mass comparable with that of a corpuscle; the
smallest positive particle of which we have any direct indication has
a mass equal to the mass of an atom of hydrogen, and it is a most
remarkable fact that we get positively charged particles having this
mass when we send the electric discharge through gases at low
pressures, whatever be the kind of gas. It is no doubt exceedingly
difficult to get rid of traces of hydrogen in vessels containing gases
at low pressures through which an electric discharge is passing, but
the circumstances under which the positively electrified particles just
alluded to appear, and the way in which they remain unaltered in
spite of all efforts to clear out any traces of hydrogen, all seem to
indicate that these positively electrified particles, whose mass is
equal to that of an atom of hydrogen, do not come from minute
traces of hydrogen present as an impurity but from the oxygen,
nitrogen, or helium, or whatever may be the gas through which the
discharge passes. If this is so, then the most natural conclusion we
can come to is that these positively electrified particles with the
mass of the atom of hydrogen are the natural units of positive
electricity, just as the corpuscles are those of negative, and that
these positive particles form a part of all atoms.
72. Thus in this way we are led to an electrical view of the
constitution of the atom. We regard the atom as built up of units of
negative electricity and of an equal number of units of positive
electricity; these two units are of very different mass, the mass of
the negative unit being only 1⁄1700 of that of the positive. The
number of units of either kind is proportional to the atomic weight of
the element and of the same order as this quantity. Whether this is
anything besides the positive and negative electricity in the atom we
do not know. In the present state of our knowledge of the properties
of matter it is unnecessary to postulate the existence of anything
besides these positive and negative units.
The atom of a chemical element on this view of the constitution of
matter is a system formed by n corpuscles and n units of positive
electricity which is in equilibrium or in a state of steady motion under
the electrical forces which the charged 2n constituents exert upon
each other. Sir J. J. Thomson (Phil. Mag., March 1904, “Corpuscular
Theory of Matter”) has investigated the systems in steady motion
which can be formed by various numbers of negatively electrified
particles immersed in a sphere of uniform positive electrification, a
case, which in consequence of the enormous volume of the units of
positive electricity in comparison with that of the negative has much
in common with the problem under consideration, and has shown
that some of the properties of n systems of corpuscles vary in a
periodic way suggestive of the Periodic Law in Chemistry as n is
continually increased.
Mass on the Electrical Theory of Matter.—One of the most
characteristic things about matter is the possession of mass. When
we take the electrical theory of matter the idea of mass takes new
and interesting forms. This point may be illustrated by the case of a
73. single electrified particle; when this moves it produces in the region
around it a magnetic field, the magnetic force being proportional to
the velocity of the electrified particle.1 In a magnetic field, however,
there is energy, and the amount of energy per unit volume at any
place is proportional to the square of the magnetic force at that
place. Thus there will be energy distributed through the space
around the moving particle, and when the velocity of the particle is
small compared with that of light we can easily show that the energy
in the region around the charged particle is μe2/3a, when v is the
velocity of the particle, e its charge, a its radius, and μ the magnetic
permeability of the region round the particle. If m is the ordinary
mass of the particle, the part of the kinetic energy due to the motion
of this mass is 1⁄2 mv2, thus the total kinetic energy is 1⁄2 (m +
2⁄3μe2/a). Thus the electric charge on the particle makes it behave
as if its mass were increased by 2⁄3μe2/a. Since this increase in mass
is due to the energy in the region outside the charged particle, it is
natural to look to that region for this additional mass. This region is
traversed by the tubes of force which start from the electrified body
and move with it, and a very simple calculation shows that we
should get the increase in the mass which is due to the
electrification if we suppose that these tubes of force as they move
carry with them a certain amount of the ether, and that this ether
had mass. The mass of ether thus carried along must be such that
the amount of it in unit volume at any part of the field is such that if
this were to move with the velocity of light its kinetic energy would
be equal to the potential energy of the electric field in the unit
volume under consideration. When a tube moves this mass of ether
only participates in the motion at right angles to the tube, it is not
set in motion by a movement of the tube along its length. We may
compare the mass which a charged body acquires in virtue of its
74. charge with the additional mass which a ball apparently acquires
when it is placed in water; a ball placed in water behaves as if its
mass were greater than its mass when moving in vacuo; we can
easily understand why this should be the case, because when the
ball in the water moves the water around it must move as well; so
that when a force acting on the ball sets it in motion it has to move
some of the water as well as the ball, and thus the ball behaves as if
its mass were increased. Similarly in the case of the electrified
particle, which when it moves carries with it its lines of force, which
grip the ether and carry some of it along with them. When the
electrified particle is moved a mass of ether has to be moved too,
and thus the apparent mass of the particle is increased. The mass of
the electrified particle is thus resident in every part of space reached
by its lines of force; in this sense an electrified body may be said to
extend to an infinite distance; the amount of the mass of the ether
attached to the particle diminishes so rapidly as we recede from it
that the contributions of regions remote from the particle are quite
insignificant, and in the case of a particle as small as a corpuscle not
one millionth part of its mass will be farther away from it than the
radius of an atom.
The increase in the mass of a particle due to given charges varies
as we have seen inversely as the radius of the particle; thus the
smaller the particle the greater the increase in the mass. For bodies
of appreciable size or even for those as small as ordinary atoms the
effect of any realizable electric charge is quite insignificant, on the
other hand for the smallest bodies known, the corpuscle, there is
evidence that the whole of the mass is due to the electric charge.
This result has been deduced by the help of an extremely interesting
property of the mass due to a charge of electricity, which is that this
mass is not constant but varies with the velocity. This comes about
75. in the following way. When the charged particle, which for simplicity
we shall suppose to be spherical, is at rest or moving very slowly the
lines of electric force are distributed uniformly around it in all
directions; when the sphere moves, however, magnetic forces are
produced in the region around it, while these, in consequence of
electro-magnetic induction in a moving magnetic field, give rise to
electric forces which displace the tubes of electric force in such a
way as to make them set themselves so as to be more at right
angles to the direction in which they are moving than they were
before. Thus if the charged sphere were moving along the line AB,
the tubes of force would, when the sphere was in motion, tend to
leave the region near AB and crowd towards a plane through the
centre of the sphere and at right angles to AB, where they would be
moving more nearly at right angles to themselves. This crowding of
the lines of force increases, however, the potential energy of the
electric field, and since the mass of the ether carried along by the
lines of force is proportional to the potential energy, the mass of the
charged particle will also be increased. The amount of variation of
the mass with the velocity depends to some extent on the
assumptions we make as to the shape of the corpuscle and the way
in which it is electrified. The simplest expression connecting the
mass with the velocity is that when the velocity is v the mass is
equal to 2⁄3μe2/a [1/(1 − v2/c2)1/2] where c is the velocity of light.
We see from this that the variation of mass with velocity is very
small unless the velocity of the body approaches that of light, but
when, as in the case of the β particles emitted by radium, the
velocity is only a few per cent less than that of light, the effect of
velocity on the mass becomes very considerable; the formula
indicates that if the particles were moving with a velocity equal to
that of light they would behave as if their mass were infinite. By
76. observing the variation in the mass of a corpuscle as its velocity
changes we can determine how much of the mass depends upon the
electric charge and how much is independent of it. For since the
latter part of the mass is independent of the velocity, if it
predominates the variation with velocity of the mass of a corpuscle
will be small; if on the other hand it is negligible the variation in
mass with velocity will be that indicated by theory given above. The
experiment of Kaufmann (Göttingen Nach., Nov. 8, 1901), Bucherer
(Ann. der Physik., xxviii. 513, 1909) on the masses of the β particles
shot out by radium, as well as those by Hupka (Berichte der
deutsch. physik. Gesell., 1909, p. 249) on the masses of the
corpuscle in cathode rays are in agreement with the view that the
whole of the mass of these particles is due to their electric charge.
The alteration in the mass of a moving charge with its velocity is
primarily due to the increase in the potential energy which
accompanies the increase in velocity. The connexion between
potential energy and mass is general and holds for any arrangement
of electrified particles; thus if we assume the electrical constitution
of matter, there will be a part of the mass of any system dependent
upon the potential energy and in fact proportional to it. Thus every
change in potential energy, such for example as occurs when two
elements combine with evolution or absorption of heat, must be
attended by a change in mass. The amount of this change can be
calculated by the rule that if a mass equal to the change in mass
were to move with the velocity of light its kinetic energy would equal
the change in the potential energy. If we apply this result to the case
of the combination of hydrogen and oxygen, where the evolution of
heat, about 1.6 × 1011 ergs per gramme of water, is greater than in
any other known case of chemical combination, we see that the
change in mass would only amount to one part in 3000 million,
77. which is far beyond the reach of experiment. The evolution of
energy by radio-active substances is enormously larger than in
ordinary chemical transformations; thus one gramme of radium
emits per day about as much energy as is evolved in the formation
of one gramme of water, and goes on doing this for thousands of
years. We see, however, that even in this case it would require
hundreds of years before the changes in mass became appreciable.
The evolution of energy from the gaseous emanation given off by
radium is more rapid than that from radium itself, since according to
the experiments of Rutherford (Rutherford, Radio-activity, p. 432) a
gramme of the emanation would evolve about 2.1 × 1016 ergs in
four days; this by the rule given above would diminish the mass by
about one part in 20,000; but since only very small quantities of the
emanation could be used the detection of the change of mass does
not seem feasible even in this case.
On the view we have been discussing the existence of potential
energy due to an electric field is always associated with mass;
wherever there is potential energy there is mass. On the electro-
magnetic theory of light, however, a wave of light is accompanied by
electric forces, and therefore by potential energy; thus waves of light
must behave as if they possessed mass. It may be shown that it
follows from the same principles that they must also possess
momentum, the direction of the momentum being the direction
along which the light is travelling; when the light is absorbed by an
opaque substance the momentum in the light is communicated to
the substance, which therefore behaves as if the light pressed upon
it. The pressure exerted by light was shown by Maxwell (Electricity
and Magnetism, 3rd ed., p. 440) to be a consequence of his electro-
78. Weight.
magnetic theory, its existence has been established by the
experiment of Lebedew, of Nichols and Hull, and of Poynting.
We have hitherto been considering mass from the point of view
that the constitution of matter is electrical; we shall proceed to
consider the question of weight from the same point of view. The
relation between mass and weight is, while the
simplest in expression, perhaps the most
fundamental and mysterious property possessed
by matter. The weight of a body is proportional to its mass, that is if
the weights of a number of substances are equal the masses will be
equal, whatever the substances may be. This result was verified to a
considerable degree of approximation by Newton by means of
experiments with pendulums; later, in 1830 Bessel by a very
extensive and accurate series of experiments, also made on
pendulums, showed that the ratio of mass to weight was certainly to
one part in 60,000 the same for all the substances examined by him,
these included brass, silver, iron, lead, copper, ivory, water.
The constancy of this ratio acquires new interest when looked at
from the point of view of the electrical constitution of matter. We
have seen that the atoms of all bodies contain corpuscles, that the
mass of a corpuscle is only 1⁄1700 of the mass of an atom of
hydrogen, that it carries a constant charge of negative electricity,
and that its mass is entirely due to this charge, and can be regarded
as arising from ether gripped by the lines of force starting from the
electrical charge. The question at once suggests itself, Is this kind of
mass ponderable? does it add to the weight of the body? and, if so,
is the proportion between mass and weight the same as for ordinary
bodies? Let us suppose for a moment that this mass is not
ponderable, so that the corpuscles increase the mass but not the
79. weight of an atom. Then, since the mass of a corpuscle is 1⁄1700 that
of an atom of hydrogen, the addition or removal of one corpuscle
would in the case of an atom of atomic weight x alter the mass by
one part in 1700 x, without altering the weight, this would produce
an effect of the same magnitude on the ratio of mass to weight and
would in the case of the atoms of the lighter elements be easily
measurable in experiments of the same order of accuracy as those
made by Bessel. If the number of corpuscles in the atom were
proportional to the atomic weight, then the ratio of mass to weight
would be constant whether the corpuscles were ponderable or not.
If the number were not proportional there would be greater
discrepancies in the ratio of mass to weight than is consistent with
Bessel’s experiments if the corpuscles had no weight. We have seen
there are other grounds for concluding that the number of
corpuscles in an atom is proportional to the atom weight, so that the
constancy of the ratio of mass to weight for a large number of
substances does not enable us to determine whether or not mass
due to charges of electricity is ponderable or not.
There seems some hope that the determination of this ratio for
radio-active substances may throw some light on this point. The
enormous amount of heat evolved by these bodies may indicate that
they possess much greater stores of potential energy than other
substances. If we suppose that the heat developed by one gramme
of a radio-active substance in the transformations which it
undergoes before it reaches the non-radio-active stage is a measure
of the excess of the potential energy in a gramme of this substance
above that in a gramme of non-radio-active substance, it would
follow that a larger part of the mass was due to electric charges in
radio-active than in non-radio-active substances; in the case of
uranium this difference would amount to at least one part in 20,000
80. of the total mass. If this extra mass had no weight the ratio of mass
to weight for uranium would differ from the normal amount by more
than one part in 20,000, a quantity quite within the range of
pendulum experiments. It thus appears very desirable to make
experiments on the ratio of mass to weight for radio-active
substances. Sir J. J. Thomson, by swinging a small pendulum whose
bob was made of radium bromide, has shown that this ratio for
radium does not differ from the normal by one part in 2000. The
small quantity of radium available prevented the attainment of
greater accuracy. Experiments just completed (1910) by Southerns
at the Cavendish Laboratory on this ratio for uranium show that it is
normal to an accuracy of one part in 200,000; indicating that in non-
radio-active, as in radio-active, substances the electrical mass is
proportional to the atomic weight.
Though but few experiments have been made in recent years on
the value of the ratio of mass to weight, many important
investigations have been made on the effect of alterations in the
chemical and physical conditions on the weight of bodies. These
have all led to the conclusion that no change which can be detected
by our present means of investigation occurs in the weight of a body
in consequence of any physical or chemical changes yet
investigated. Thus Landolt, who devoted a great number of years to
the question whether any change in weight occurs during chemical
combination, came finally to the conclusion that in no case out of
the many he investigated did any measurable change of weight
occur during chemical combination. Poynting and Phillips (Proc. Roy.
Soc., 76, p. 445), as well as Southerns (78, p. 392), have shown
that change in temperature produces no change in the weight of a
body; and Poynting has also shown that neither the weight of a
crystal nor the attraction between two crystals depends at all upon
81. the direction in which the axis of the crystal points. The result of
these laborious and very carefully made experiments has been to
strengthen the conviction that the weight of a given portion of
matter is absolutely independent of its physical condition or state of
chemical combinations. It should, however, be noticed that we have
as yet no accurate investigation as to whether or not any changes of
weight occur during radio-active transformations, such for example
as the emanation from radium undergoes when the atoms
themselves of the substance are disrupted.
It is a matter of some interest in connexion with a discussion of
any views of the constitution of matter to consider the theories of
gravitation which have been put forward to explain that apparently
invariable property of matter—its weight. It would be impossible to
consider in detail the numerous theories which have been put
forward to account for gravitation; a concise summary of many of
these has been given by Drude (Wied. Ann. 62, p. 1);2 there is no
dearth of theories as to the cause of gravitation, what is lacking is
the means of putting any of them to a decisive test.
There are, however, two theories of gravitation, both old, which
seem to be especially closely connected with the idea of the
electrical constitution of matter. The first of these is the theory,
associated with the two fluid theory of electricity, that gravity is a
kind of residual electrical effect, due to the attraction between the
units of positive and negative electricity being a little greater than
the repulsion between the units of electricity of the same kind. Thus
on this view two charges of equal magnitude, but of opposite sign,
would exert an attraction varying inversely as the square of the
distance on a charge of electricity of either sign, and therefore an
attraction on a system consisting of two charges equal in magnitude
82. but opposite in sign forming an electrically neutral system. Thus if
we had two neutral systems, A and B, A consisting of m positive
units of electricity and an equal number of negative, while B has n
units of each kind, then the gravitational attraction between A and B
would be inversely proportional to the square of the distance and
proportional to n m. The connexion between this view of gravity and
that of the electrical constitution of matter is evidently very close, for
if gravity arose in this way the weight of a body would only depend
upon the number of units of electricity in the body. On the view that
the constitution of matter is electrical, the fundamental units which
build up matter are the units of electric charge, and as the
magnitude of these charges does not change, whatever chemical or
physical vicissitudes matter, the weight of matter ought not to be
affected by such changes. There is one result of this theory which
might possibly afford a means of testing it: since the charge on a
corpuscle is equal to that on a positive unit, the weights of the two
are equal; but the mass of the corpuscle is only 1⁄1700 of that of the
positive unit, so that the acceleration of the corpuscle under gravity
will be 1700 times that of the positive unit, which we should expect
to be the same as that for ponderable matter or 981.
The acceleration of the corpuscle under gravity on this view would
be 1.6 × 106. It does not seem altogether impossible that with
methods slightly more powerful than those we now possess we
might measure the effect of gravity on a corpuscle if the acceleration
were as large as this.
The other theory of gravitation to which we call attention is that
due to Le Sage of Geneva and published in 1818. Le Sage supposed
that the universe was thronged with exceedingly small particles
moving with very great velocities. These particles he called ultra-
83. mundane corpuscles, because they came to us from regions far
beyond the solar system. He assumed that these were so
penetrating that they could pass through masses as large as the sun
or the earth without being absorbed to more than a very small
extent. There is, however, some absorption, and if bodies are made
up of the same kind of atoms, whose dimensions are small
compared with the distances between them, the absorption will be
proportional to the mass of the body. So that as the ultra-mundane
corpuscles stream through the body a small fraction, proportional to
the mass of the body, of their momentum is communicated to it. If
the direction of the ultra-mundane corpuscles passing through the
body were uniformly distributed, the momentum communicated by
them to the body would not tend to move it in one direction rather
than in another, so that a body, A, alone in the universe and exposed
to bombardment by the ultra-mundane corpuscles would remain at
rest. If, however, there were a second body, B, in the neighbourhood
of A, B will shield A from some of the corpuscles moving in the
direction BA; thus A will not receive as much momentum in this
direction as when it was alone; but in this case it only received just
enough to keep it in equilibrium, so that when B is present the
momentum in the opposite direction will get the upper hand and A
will move in the direction AB, and will thus be attracted by B.
Similarly, we see that B will be attracted by A. Le Sage proved that
the rate at which momentum was being communicated to A or B by
the passage through them of his corpuscles was proportional to the
product of the masses of A and B, and if the distance between A and
B was large compared with their dimensions, inversely proportional
to the square of the distance between them; in fact, that the forces
acting on them would obey the same laws as the gravitational
attraction between them. Clerk Maxwell (article “Atom,” Ency. Brit.,
84. 9th ed.) pointed out that this transference of momentum from the
ultra-mundane corpuscles to the body through which they passed
involved the loss of kinetic energy by the corpuscles, and if the loss
of momentum were large enough to account for the gravitational
attraction, the loss of kinetic energy would be so large that if
converted into heat it would be sufficient to keep the body white
hot. We need not, however, suppose that this energy is converted
into heat; it might, as in the case where Röntgen rays are produced
by the passage of electrified corpuscles through matter, be
transformed into the energy of a still more penetrating form of
radiation, which might escape from the gravitating body without
heating it. It is a very interesting result of recent discoveries that the
machinery which Le Sage introduced for the purpose of his theory
has a very close analogy with things for which we have now direct
experimental evidence. We know that small particles moving with
very high speeds do exist, that they possess considerable powers of
penetrating solids, though not, as far as we know at present, to an
extent comparable with that postulated by Le Sage; and we know
that the energy lost by them as they pass through a solid is to a
large extent converted into a still more penetrating form of radiation,
Röntgen rays. In Le Sage’s theory the only function of the corpuscles
is to act as carriers of momentum, any systems which possessed
momentum, moved with a high velocity and had the power of
penetrating solids, might be substituted for them; now waves of
electric and magnetic force, such as light waves or Röntgen rays,
possess momentum, move with a high velocity, and the latter at any
rate possess considerable powers of penetration; so that we might
formulate a theory in which penetrating Röntgen rays replaced Le
Sage’s corpuscles. Röntgen rays, however, when absorbed do not, as
far as we know, give rise to more penetrating Röntgen rays as they
85. should to explain attraction, but either to less penetrating rays or to
rays of the same kind.
We have confined our attention in this article to the view that the
constitution of matter is electrical; we have done so because this
view is more closely in touch with experiment than any other yet
advanced. The units of which matter is built up on this theory have
been isolated and detected in the laboratory, and we may hope to
discover more and more of their properties. By seeing whether the
properties of matter are or are not such as would arise from a
collection of units having these properties, we can apply to this
theory tests of a much more definite and rigorous character than we
can apply to any other theory of matter.
(J. J. T.)
1 We may measure this velocity with reference to any axes, provided
we refer the motion of all the bodies which come into consideration to
the same axes.
2 A theory published after Drude’s paper in that of Professor Osborne
Reynolds, given in his Rede lecture “On an Inversion of Ideas as to the
Structure of the Universe.”
MATTERHORN, one of the best known mountains (14,782
ft.) in the Alps. It rises S.W. of the village of Zermatt, and on the
frontier between Switzerland (canton of the Valais) and Italy. Though
86. on the Swiss side it appears to be an isolated obelisk, it is really but
the butt end of a ridge, while the Swiss slope is not nearly as steep
or difficult as the grand terraced walls of the Italian slope. It was
first conquered, after a number of attempts chiefly on the Italian
side, on the 14th of July 1865, by Mr E. Whymper’s party, three
members of which (Lord Francis Douglas, the Rev. C. Hudson and Mr
Hadow) with the guide, Michel Croz, perished by a slip on the
descent. Three days later it was scaled from the Italian side by a
party of men from Val Tournanche. Nowadays it is frequently
ascended in summer, especially from Zermatt.
MATTEUCCI, CARLO (1811-1868), Italian physicist, was
born at Forlì on the 20th of June 1811. After attending the École
Polytechnique at Paris, he became professor of physics successively
at Bologna (1832), Ravenna (1837) and Pisa (1840). From 1847 he
took an active part in politics, and in 1860 was chosen an Italian
senator, at the same time becoming inspector-general of the Italian
telegraph lines. Two years later he was minister of education. He
died near Leghorn on the 25th of June 1868.
He was the author of four scientific treatises: Lezioni di fisica
(2 vols., Pisa, 1841), Lezioni sui fenomeni fisicochimici dei corpi
viventi (Pisa, 1844), Manuale di telegrafia elettrica (Pisa, 1850)
and Cours spécial sur l’induction, le magnetisme de rotation, &c.
87. (Paris, 1854). His numerous papers were published in the
Annales de chimie et de physique (1829-1858); and most of
them also appeared at the time in the Italian scientific journals.
They relate almost entirely to electrical phenomena, such as the
magnetic rotation of light, the action of gas batteries, the effects
of torsion on magnetism, the polarization of electrodes, &c.,
sufficiently complete accounts of which are given in
Wiedemann’s Galvanismus. Nine memoirs, entitled “Electro-
Physiological Researches,” were published in the Philosophical
Transactions, 1845-1860. See Bianchi’s Carlo Matteucci e l’Italia
del suo tempo (Rome, 1874).
MATTHEW, ST (Μαθθαῖος or Ματθαῖος, probably a
shortened form of the Hebrew equivalent to Theodorus), one of the
twelve apostles, and the traditional author of the First Gospel, where
he is described as having been a tax-gatherer or customs-officer
(τελώνης, x. 3), in the service of the tetrarch Herod. The
circumstances of his call to become a follower of Jesus, received as
he sat in the “customs house” in one of the towns by the Sea of
Galilee—apparently Capernaum (Mark ii. 1, 13), are briefly related in
ix. 9. We should gather from the parallel narrative in Mark ii. 14,
Luke v. 27, that he was at the time known as “Levi the son of
Alphaeus” (compare Simon Cephas, Joseph Barnabas): if so, “James
the son of Alphaeus” may have been his brother. Possibly “Matthew”
88. (Yahweh’s gift) was his Christian surname, since two native names,
neither being a patronymic, is contrary to Jewish usage. It must be
noted, however, that Matthew and Levi were sometimes
distinguished in early times, as by Heracleon (c. 170 a.d.), and more
dubiously by Origen (c. Celsum, i. 62), also apparently in the Syriac
Didascalia (sec. iii.), V. xiv. 14. It has generally been supposed, on
the strength of Luke’s account (v. 29), that Matthew gave a feast in
Jesus’ honour (like Zacchaeus, Luke xix. 6 seq.). But Mark (ii. 15),
followed by Matthew (ix. 10), may mean that the meal in question
was one in Jesus’ own home at Capernaum (cf. v. 1). In the lists of
the Apostles given in the Synoptic Gospels and in Acts, Matthew
ranks third or fourth in the second group of four—a fair index of his
relative importance in the apostolic age. The only other facts related
of Matthew on good authority concern him as Evangelist. Eusebius
(H.E. iii. 24) says that he, like John, wrote only at the spur of
necessity. “For Matthew, after preaching to Hebrews, when about to
go also to others, committed to writing in his native tongue the
Gospel that bears his name; and so by his writing supplied, for those
whom he was leaving, the loss of his presence.” The value of this
tradition, which may be based on Papias, who certainly reported that
“Matthew compiled the Oracles (of the Lord) in Hebrew,” can be
estimated only in connexion with the study of the Gospel itself (see
below). No historical use can be made of the artificial story, in
Sanhedrin 43a, that Matthew was condemned to death by a Jewish
court (see Laihle, Christ in the Talmud, 71 seq.). According to the
Gnostic Heracleon, quoted by Clement of Alexandria (Strom. iv. 9),
Matthew died a natural death. The tradition as to his ascetic diet (in
Clem. Alex. Paedag. ii. 16) maybe due to confusion with Matthias (cf.
Mart. Matthaei, i.). The earliest legend as to his later labours, one of
Syrian origin, places them in the Parthian kingdom, where it
89. Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
ebookbell.com