sasautos extensions

[This site is not connected with the SAS Institute]

(Last updated: 08 September 2007)

[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.

Introduction

Let me explain very briefly why I have titled this page "sasautos extensions". Simply, these are the macros I wish I had in my sasautos library. What you find in the sasautos library, as supplied, is arbitrary. You have utility macros like %lowcase there but the very useful %words macro is missing. There is no logic to it. Instead, it is up to you to decide what to make available. A set of useful utility macros could save you a lot of time as a programmer, and if you are intending to write more complex macros then you will often wish you had a set of utility macros to use as building blocks as sometimes this is the only way you can cope with the complexity of the task. So my suggestion is for you to create your own sasautos library with all the macros you need in it and either use that instead of the SI supplied library or add it to the sasautos path before the SI supplied sasautos library.

On this page I have split the macros into three sections as some are clearly to do with getting data set and variable information and some are function-style macros that distill into a result that you assign to a macro variable so I have shown these first. This may or may not be of help to you. If you want to browse the alphabetical list of all macros on this web site, as well as their purposes, and be able to link to them, then click on the link here.

Data set 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 data set
testpack - attrn - low level macro called by other macros that returns numeric information about a data set
testpack - attrv - low level macro called by other macros that returns variable information
testpack - crdte - return the creation date of a data set as a number
testpack - dslabel - return a data set label
testpack - dsall - expands out the _all_ notation into data set names
testpack - dslist - list all data sets under a given libref
testpack - getvalue - returns the value of a variable
testpack - hasvars - returns true if data set has all variables in supplied list
testpack - hasvarsc - returns true if data set has all character variables in supplied list
testpack - hasvarsn - returns true if data set has all numeric variables in supplied list
testpack - modte - return the modification date of a data set as a number
testpack - nlobs - return the number of logical observations (i.e. not marked for deletion) in a data set
testpack - nobs - return the number of observations in a data set
testpack - nvars - return the number of variables in a data set
testpack - nvarsc - return the number of character variables in a data set
testpack - nvarsn - return the number of numeric variables in a data set
testpack - putvars - lists all dataset variables followed by an equals sign for use in a put statement (NEW !!)
testpack - sortedby - lists the variables a dataset is sorted by (NEW !!)
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 data set
testpack - varlistc - return a list of all character variables in a data set
testpack - varlistn - return a list of all numeric variables in a data set
testpack - varnum - return a variable's position in a data set (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 - capmac - to capitalize the first letter of each word in a macro string (NEW !!)
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 - fmtpath - gives the current full fmtsearch path (NEW !!)
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 - leftleft-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 - 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 - 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 - substrw - works like the %substr() function but acts on words in a macro string (NEW !!)
testpack - therest - returns everything in a macro expression following one of the target characters
testpack - trimtrims a macro variable string
testpack - unimap - maps freestyle stats labels to their statistics keywords (NEW !!)
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 - allfmtvals - creates a dataset with all the start values of a format in it (NEW !!)
testpack - alluniq - writes all unique values of a variable in a whole library to a data set
testpack - asciinonp - show up all non-printable ascii character in a flat file (NEW !!)
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 - capvar - to capitalize the first letter of each word of a string assigned to a character variable (NEW !!)
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 data sets
testpack - complibs - compares like-named data sets in two libraries
testpack - delhex - remove a specified hex character from a flat file
testpack - delzero - illustration macro to delete all datasets with zero observations in a library (NEW !!)
testpack - doallitem - execute code for each item in a space-delimited list
testpack - dropvars - drop unwanted variables in a list of data sets
testpack - dsattrib - assigns the attributes of one data set onto another data set
testpack - dtscale - calculates a suitable haxis date scale given a min and max date
testpack - duplvars - identifies which variables are duplicated in a second data set
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 - fmtord - create a numeric informat that maps a format label to its position (NEW !!)
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 - hexcnt - counts strange hex characters in character variables (NEW !!)
testpack - jobinfo - stores important job information in global macro variables
testpack - lafootnote - left-aligns a footnote for a plain text report
testpack - latitle - left-aligns a title for a plain text report
testpack - lrafootnote - left and right-aligns a two part footnote for a plain text report
testpack - lratitle - left and right-aligns a two part title for a plain text report
testpack - ljustify - left-justifies all character fields in a data set
testpack - lookahead - the opposite of lag(), this looks ahead in a data set
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 data set 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 - rafootnote - right-aligns a footnote for a plain text report
testpack - ratitle - right-aligns a title for a plain text report
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 data sets
testpack - sasindex - utility to index your sas programs
testpack - showhex - creates a new dataset where hex characters in character variables are highlighted (NEW !!)
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 data sets by the specified "by" variablesif they exist in the data sets
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 - zeroize a variable for all combinations of distinct variable values in multiple data sets

Go back to the home page.

E-mail the macro and web site author.