sasautos extensions

[This site is not connected with the SAS Institute]

(Last updated: 05 September 2003 - %clength, %ljustify, %optlength and %chompw added)

[Please note that the code on this web site is intended to run under SAS version 8.1 or later]

[Disclaimer: You will be able to access and download public domain code from this page. Although efforts have been made to test the code, no guarantee as to suitability or accuracy is either given or implied. If you use the code, you do so at your own risk. You should test this code yourself and thoroughly satisfy yourself that it is working correctly before using it in a production environment. If you find problems in the code then please inform the author using the contact email address in the header of the macro].

Note that these were written on a Windows PC. If you download these files directly to a different platform such as Unix then you might get problems with the control characters at the end of the lines. You might be better off just copying and pasting if you are not running Windows. If you do copy and paste then choose the browser option to view the source of the macro and copy and paste that. This is because some of the macro variable references get translated into something else by the browser.

All these macros have html tags as part of the header box and will appear as <pre><b> in the first line. They are not part of the code. They just help them to display correctly when you browse them using web pages. You should remove these tag markers if you intend to use the macros, although they will not affect the code since they are part of the commented-out header.

The entire set of sasautos extensions (as well as some clinical reporting macros) can be downloaded in zipped format by clicking on this link.

dataset and variable information macros

Test Pack - Actual Macro - Description of function
testpack - attrc - low level macro called by other macros that returns character information about a dataset
testpack - attrn - low level macro called by other macros that returns numeric information about a dataset
testpack - attrv - low level macro called by other macros that returns variable information
testpack - crdte - return the creation date of a dataset as a number
testpack - dslabel - return a dataset label
testpack - dsall - expands out the _all_ notation into dataset names
testpack - dslist - list all datasets under a given libref
testpack - getvalue - returns the value of a variable
testpack - hasvars - returns true if dataset has all variables in supplied list
testpack - hasvarsc - returns true if dataset has all character variables in supplied list
testpack - hasvarsn - returns true if dataset has all numeric variables in supplied list
testpack - modte - return the modification date of a dataset as a number
testpack - nlobs - return the number of logical observations (i.e. not marked for deletion) in a dataset
testpack - nobs - return the number of observations in a dataset
testpack - nvars - return the number of variables in a dataset
testpack - nvarsc - return the number of character variables in a dataset
testpack - nvarsn - return the number of numeric variables in a dataset
testpack - varfmt - return a variable's format
testpack - varinfmt - return a variable's informat
testpack - varlabel - return a variable's label
testpack - varlen - return a variable's length
testpack - varlist - return a list of all variables in a dataset
testpack - varlistc - return a list of all character variables in a dataset
testpack - varlistn - return a list of all numeric variables in a dataset
testpack - varnum - return a variable's position in a dataset (or 0 if not present)
testpack - vartype - return a "C" or "N" depending on the type of a variable

other function-style small utility macros

Test Pack - Actual Macro - Description of function
testpack - addautos - adds an extra library to the front or back of the sasautos search path
testpack - after - returns the word or quote that directly follows a target string
testpack - casestrmac - change a mixed-case version of a string to the string itself for a macro expression
testpack - chompw - to "chomp" a word and optionally before and/or after words out of a macro string
testpack - compress - compress a macro string for specified characters
testpack - commas - delimits elements of a list with commas
testpack - endwith - ensures a macro string ends with a specified character if not null
testpack - eqsuff - suffix elements of a list with equal signs
testpack - globexist - test for the existence of all of one or more global macro variables
testpack - globlist - return a list of all current global macro variables in uppercase
testpack - left -  left-aligns a macro variable string
testpack - lowcase - lower-case the contents of a macro variable
testpack - match - return elements of a list that match with those in a reference list
testpack - nodup - return a list with duplicate items removed
testpack - noquotes - removes all quoted strings from a macro expression
testpack - qcompress - compresses a macro variable and returns results quoted
testpack - qleft - left-aligns a macro string and returns the result quoted
testpack - qtrim - trims a macro variable string and returns the results quoted
testpack - quotelst - quotes elements of a list
testpack - quotecnt - counts quoted elements in a macro expression
testpack - quotescan - scans for quoted elements in a macro expression
testpack - remove - removes a target string from another string
testpack - rxmatch - return matching elements of a list according to the specified RX pattern
testpack - splitmac - insert split characters into a macro string
testpack - therest - returns everything in a macro expression following one of the target characters
testpack - trim -  trims a macro variable string
testpack - verify - returns the first position in a macro string where the character does not match a supplied list
testpack - verifyb - backwards equivalent of the verify macro
testpack - windex - return the position of a word count in a string
testpack - words - counts the number of words (strings delimited by spaces) in a list

other utility macros

Test Pack - Actual Macro - Description of function
testpack - age - returns the age of a person at a specified date (for use in a data step)
testpack - aligndp - formats numeric values into a text field aligning decimal points
testpack - alluniq - writes all unique values of a variable in a whole library to a dataset
testpack - bydrop - drop by-group residual observations
testpack - bytitle - drop the last title if it is a "by" title and write the contents away
testpack - casestrvar - change a mixed-case version of a string to the string itself for a text variable (for use in a data step)
testpack - char2num - to "effectively" change numeric-containing character variables to numeric variables
testpack - chkuniq - check for uniqueness in key variables
testpack - clashvars - to identify where there is a clash of variable characteristics within a library
testpack - clength - to create a length statement for the maximum length of identical character variables in multiple datasets
testpack - complibs - compares like-named datasets in two libraries
testpack - delhex - remove a specified hex character from a flat file
testpack - doallitem - execute code for each item in a space-delimited list
testpack - dropvars - drop unwanted variables in a list of datasets
testpack - dsattrib - assigns the attributes of one dataset onto another dataset
testpack - dtscale - calculates a suitable haxis date scale given a min and max date
testpack - duplvars - identifies which variables are duplicated in a second dataset
testpack - equals - tests for equality or very near equality (for use in a data step)
testpack - fixvars - "fixes" variables throughout a library so that the label, format and length is the same
testpack - flatten - "flattens" data so that there is only one observation per by group
testpack - fmts2fda - creates code to create formats you use so you can send it to the FDA
testpack - hexchars - displays non-printable ascii characters in a flat file as hex codes
testpack - jobinfo - stores important job information in global macro variables
testpack - ljustify - left-justifies all character fields in a dataset
testpack - lookahead - the opposite of lag(), this looks ahead in a dataset
testpack - ltgtm1 - adjusts for leading ">" and "<" signs
testpack - maxtitle - gives the number of the maximum title and footnote
testpack - misscnt - identifies variables and their missing-value count
testpack - missvars - identifies variables that are all-missing
testpack - mkformat - make a format out of a dataset coded and decoded variable
testpack - nodata - produces a "no data" report if there are no observation to meet a criterion
testpack - nodupkey - sorts "nodupkey" and lists all observations being dropped
testpack - numchars - identifies character variables that likely contain text numbers only
testpack - optlength - creates a length statement for character variables that take up less space than allotted
testpack - pagexofy - puts "Page x of y" labels in a flat file
testpack - printall - prints every observation in a library that satisfies a condition on a variable
testpack - readfile - reads in a file and assigns the contents to a macro variable
testpack - readpipe - reads in the output of a System command and assigns it to a macro variable
testpack - replhex - replace all occurrences of a specified hex character in a flat file with another specified character
testpack - round - round all the numeric variables in a list of datasets
testpack - sasindex - utility to index your sas programs
testpack - splitvar - insert split characters into variable text (for use in a data step)
testpack - subspace - substitutes a space for a special character in a flat file
testpack - supasort - sorts a list of datasets by the specified "by" variables if they exist in the datasets
testpack - titlelen - makes a copy of sashelp.vtitle but with the original length added
testpack - vaxis - calculates a suitable vaxis scale given a min and max value
testpack - yrcutoff - sets the yearcutoff option to one suitable for clinical reporting
testpack - zerogrid - zeroises a variable for all combinations of distinct variable values in multiple datasets

Go back to the home page.

E-mail the macro and web site author.