Source: http://checklog.cswenson.com/downloads/macros
Timestamp: 2019-04-20 08:11:11+00:00

Document:
The following macro programs are for general use. See the descriptions for more information.
Note: The ~Messages.txt file is a dummy file for adding custom notes for the update email.
View Download Note: The recent update to the DupCheck macro modified the default value of the SORT= argument and added a new argument, SMALL=. Please read the header for more documentation. 1k v. 10 Apr 5, 2012, 10:05 AM Chris S.
Download Add a format library while retaining the libraries already specified. 2k v. 11 Nov 11, 2011, 9:42 AM Chris S.
Download Add a SAS autocall macro fileref while retaining the filerefs already specified. 2k v. 12 Feb 16, 2016, 2:09 PM Chris S.
Download Calculate age based on a specified date. Obtained from the SAS Institute website. 2k v. 6 Nov 28, 2010, 6:16 AM Chris S.
Download Generate code to check macro arguments for blanks. 2k v. 11 Jun 3, 2011, 4:25 PM Chris S.
Download Check the current SAS log, an external log, or a directory of logs for issues, including error, warning, invalid, and uninitialized messages as well as a list of phrases usually associated with issues. See CheckLog sidebar for full documentation: http://sas.cswenson.com/checklog/ 86k v. 40 Apr 13, 2018, 6:48 AM Chris S.
Download Write messages in the log in color (red, blue, or green). 2k v. 7 Nov 28, 2010, 6:16 AM Chris S.
Download Compare the contents to two data sets to determine differences. The data sets should be similar; otherwise, many differences will arise. UPDATE: Added the LIB= argument to specify the temporary and output library (defaulted to WORK). 16k v. 16 Sep 28, 2017, 2:50 PM Chris S.
Download Compress a data set using character or binary compression. 5k v. 11 Dec 22, 2011, 9:26 AM Chris S.
Download Convert variables from character to numeric, numeric to character, date to datetime, and datetime to date types. 4k v. 10 Jun 28, 2011, 11:16 AM Chris S.
Download Copy data from one library to another, using either PROC DATASETS or the DATA step, with optional compression, selection of data sets, and deletion of the source library. 5k v. 7 Nov 28, 2010, 6:17 AM Chris S.
Download Copy a file using the operating system. 3k v. 7 Feb 16, 2016, 2:33 PM Chris S.
Download Copy the path of a libref or fileref to the clipboard. 1k v. 4 Aug 5, 2011, 7:41 AM Chris S.
Download Use the COUNTW function in SAS 9.2+ and an alternative in prior versions. Limitation: Only uses 1 delimiter. 2k v. 4 Aug 5, 2011, 7:41 AM Chris S.
Download Use the DatePart function without generating an issue in the log when missing values are encountered. 3k v. 2 Aug 23, 2011, 9:39 AM Chris S.
Download Delete macro variables with an option to exclude specific macro variables. Inspired by a macro from the SAS Institute website. 3k v. 10 Mar 1, 2012, 12:43 PM Chris S.
Download Obtain a directory listing using a Windows command. Optionally filter by the file extension, file size, and date/time. Originally written by Ross Bettinger with my revisions. 14k v. 6 Nov 11, 2011, 9:43 AM Chris S.
Download Drop one or more tables using SQL. 2k v. 9 Dec 28, 2011, 2:13 PM Chris S.
Download Obtain a distinct count of a specified variable with options to create an output macro variable and filter the input data set. 2k v. 10 Nov 11, 2011, 9:41 AM Chris S.
Download Check for duplicates within a data set with multiple options, including an option to split the distinct records from the duplicate records, suggest which variable(s) may be involved in duplication (requires the DupVar macro), and the ability to flag the output as expected. 19k v. 31 Feb 16, 2016, 2:33 PM Chris S.
Download Identify variables that may be involved in duplication. Used in the DupCheck macro. 5k v. 12 Jul 20, 2011, 7:52 AM Chris S.
Download Send an email with a few options, like attachments. 4k v. 4 Aug 5, 2011, 7:42 AM Chris S.
Download Check if a directory exists. 2k v. 8 Feb 16, 2016, 2:34 PM Chris S.
Download Check if a file exists. 2k v. 8 Feb 16, 2016, 2:34 PM Chris S.
Download Check if a variable exists. 3k v. 4 Aug 5, 2011, 7:42 AM Chris S.
Download Output the extension of a file. 2k v. 4 Aug 5, 2011, 7:42 AM Chris S.
Download Find a table in a library. 3k v. 8 Nov 29, 2010, 2:28 PM Chris S.
Download Find a variable in a library. 3k v. 8 Nov 29, 2010, 2:28 PM Chris S.
Download Output a list of variables and their formats for pasting into a format statement. 3k v. 4 Aug 5, 2011, 7:42 AM Chris S.
Download Output frequencies of one or more variables to data sets named after the variable, with the option to split by a variable. 5k v. 17 Feb 3, 2012, 9:40 AM Chris S.
Download Output frequencies for all variables in a data set, sent to one master data set. 9k v. 5 Feb 16, 2016, 2:34 PM Chris S.
Download Find the current setting for a SAS option and optionally save the value in a macro variable. 2k v. 8 Mar 2, 2011, 7:08 PM Chris S.
Download Write a message to the log when specific criteria are met. Optionally designate the message as an issue (error/warning) or output a message when the criteria are not met. 2k v. 9 Dec 29, 2010, 7:15 AM Chris S.
Download Create a macro variable that is a list of values from a column in a data set. Optionally define the delimiter and filter the input data set. 14k v. 18 Feb 16, 2016, 2:34 PM Chris S.
Download Turn on/off the SAS log. 2k v. 8 Jun 3, 2011, 4:47 PM Chris S.
Download Generate a list of variables for a keep statement (or other statements). 3k v. 4 Aug 5, 2011, 7:43 AM Chris S.
Download Deprecated: See PrintContents. 1k v. 9 Feb 3, 2012, 10:00 AM Chris S.
Download Output the maximum lengths for variables in a data set. 4k v. 1 Feb 3, 2012, 9:45 AM Chris S.
Download Count the number of observations in all data sets in a library. 5k v. 11 Dec 28, 2011, 2:13 PM Chris S.
Download Split the library and table into macro variables for later reference. Useful when a specified argument needs to be split to output the data somewhere other than the source (e.g., when the source is read-only). 2k v. 9 Feb 16, 2016, 2:34 PM Chris S.
Download Use a Windows message box with options for the message, title, buttons, icon, and the type of execution (macro or DATA step). This macro requires that the Windows API code be stored in a permanent location (e.g., the USER library). Open the macro to view the API code. 11k v. 16 Apr 11, 2012, 10:44 AM Chris S.
Download Output the minimum and maximum dates. Able to handle text dates when the format is specified. 5k v. 9 Feb 16, 2016, 2:35 PM Chris S.
Download Set date and time for code to execute. The macro should be executed along with the code to run at the specified time. This macro is useful when scheduling tasks is not available. 4k v. 10 Nov 11, 2011, 9:42 AM Chris S.
Download Output the number of observations. This macro was found on the SAS Institute website, and it is included here due to its pervasive use within other macros. 2k v. 9 Jul 20, 2011, 7:54 AM Chris S.
Download Remove labels from variables in one or more data sets. 2k v. 9 Jul 20, 2011, 7:54 AM Chris S.
Download Convert numbers to "names", for example, 100 is converted to "one hundred". Limited to 21 digits. 9k v. 9 Dec 17, 2010, 12:21 PM Chris S.
Download Similar to the NObs macro, this macro outputs the number of variables in a data set. 2k v. 8 Jul 20, 2011, 7:54 AM Chris S.
Download Set observations in a data set to macro variables, using a specified prefix and the observation number to create the macro variable name. Optionally filter the input data set. 9k v. 17 Apr 3, 2012, 7:54 AM Chris S.
Download Open the properties of the specified table. If blank, the last or copied table will be used. Based on the OpenTable macro. 9k v. 3 Dec 28, 2011, 2:13 PM Chris S.
Download Open a specified table, the last table, or the table copied to the clipboard. Uses the API in the MessageBox macro or a %WINDOW statement. Please review the code and decide which method to use. The macro is very efficient when a library has many tables. 11k v. 15 May 7, 2012, 6:58 AM Chris S.
Download Post a message using a pop-up. Similar to the MessageBox macro, but simpler (with fewer options) and not requiring the use of a Windows API. 1k v. 9 Mar 4, 2011, 1:37 PM Chris S.
Download Print the contents of the specified table(s). 10k v. 7 Dec 28, 2011, 2:13 PM Chris S.
Download Print specific types of objects to the SAS log using information from SASHELP.VCATALG. 2k v. 10 Apr 3, 2012, 7:52 AM Chris S.
Download Compare the counts in two data sets, defaulted to checking for equality. Can be checked for any of the number comparison operators using the mnemonics (e.g., EQ for =, LT for <) as an argument. 5k v. 4 May 19, 2011, 7:16 AM Chris S.
Download Generate a set of random data using one of two methods: sorting (type 1) or by selecting random observations (type 2), which is much faster. Uses the TIME macro. 4k v. 16 Feb 16, 2016, 2:35 PM Chris S.
Download Rename variables in a data set based on mapping specified in a data set called RenameVars, with the option to filter the RenameVars data set. This is useful when renaming multiple data sets using a common mapping document. 6k v. 10 Jul 20, 2011, 7:54 AM Chris S.
Download Reorder the variables in a data set. 4k v. 10 Feb 16, 2016, 2:35 PM Chris S.
Download Save the SAS log to a specified location, optionally appending datetime text at the level of year, quarter, month, day, or time. 5k v. 12 May 7, 2012, 6:58 AM Chris S.
Download Search through code or a directory of code for a term with an option to search sub-directories. This is useful when Windows does not index SAS code for searching (e.g., on network drives). 14k v. 18 Mar 1, 2012, 12:44 PM Chris S.
Download Generate a SQL select statement from an input data set. 3k v. 7 Nov 11, 2011, 9:41 AM Chris S.
Download Select records with the min, max, or other statistic of a value. 4k v. 4 Aug 5, 2011, 7:44 AM Chris S.
Download Create one or more macro variables from the variable names in a data set. The generated macro variable can either be a list within one macro variable or multiple macro variables named with the specified prefix and appended observation number. 16k v. 18 May 16, 2012, 2:01 PM Chris S.
Download Download and include the macros on this site! Include specific macros or all macros, and optionally force the source code to be printed (single macros only). Additionally, save the macros to an autocall library or store them in a compiled macro catalog (06/08/2011). Added better processing in the UNIX environment (08/08/2011). 14k v. 16 Apr 3, 2012, 7:53 AM Chris S.
Download Sort and compare data sets using PROC COMPARE, which requires sorted data. Eliminates repetitive coding. Optionally excludes specific variables. The macro also identifies and splits out records that exist in one or the other data set for examination. This macro is useful to verify that two data sets are identical. UPDATE: Added LIB= argument to specify the temporary file and output library (defaulted to WORK). 16k v. 27 Sep 28, 2017, 2:55 PM Chris S.
Download Output information about a table. 3k v. 10 Feb 3, 2012, 9:40 AM Chris S.
Download Generate macro variables for tables identified from SASHELP.VTABLE, naming the variables using the specified prefix and the observation number of the table. Useful when processing multiple data sets. Similar to ObsMac, but with a static source table. 8k v. 12 Feb 16, 2016, 2:36 PM Chris S.
Download Time tea brewing using SAS. Allows for 1 to 10 minutes. Useful when the user cannot install software. Can use the MessageBox macro. Now with sound option! 4k v. 10 Jan 21, 2011, 2:32 PM Chris S.
Download Export data to a tab-delimited text file. 2k v. 8 Jul 20, 2011, 7:55 AM Chris S.
Download Convert a (completely) text value to an ID that will be the same for the specific text each time it is run. This process can be valuable for adding an ID to a text value when no ID exists, and the same ID is needed for the same text values and each time it is run.Note that the macro is case sensitive, so if upper- and lower-case text need to have the same ID, the input data set should be modified first. The macro converts the text to its binary representation then sums up the numeric value for the entire field.Warning: If the input value contains numbers, it is possible the output may not be distinct by the input, since the sum of some numbers could be the same. This process is best for converting categories (i.e., alphabetic values only) to an ID. 4k v. 7 Feb 3, 2012, 9:40 AM Chris S.
Download Insert the current time into the log. Additionally, evaluate the time since the last run, output a note with the time, and log the time in a data set called Log_Time. 6k v. 11 Feb 16, 2016, 2:36 PM Chris S.
Download Transpose all columns in a data set, based on by variable(s) and an ID variable (for PROC TRANSPOSE), and re-merge all the columns back into one data set. The names of the columns are set to the original name as a prefix, with the ID added at the end, and an optional suffix. 11k v. 3 Apr 3, 2012, 7:53 AM Chris S.
Download Validate arguments for macro programs by writing code to look for blanks and invalid values, either Y/N or a specified list. 10k v. 6 Apr 3, 2012, 7:54 AM Chris S.
Download Count the number of populated variables in a data set. 6k v. 9 Aug 2, 2013, 9:53 AM Chris S.
Download Output information on a variable. Similar to NObs and NVars, but with the ability to output more types of information. 3k v. 8 Jul 20, 2011, 7:55 AM Chris S.
Download Create macro variables from two columns, where one column names the macro variable and another supplies the value. Optionally filter the input data set. 7k v. 11 Apr 3, 2012, 7:53 AM Chris S.
Download Output a format to a data set for viewing. 3k v. 8 Apr 3, 2012, 7:53 AM Chris S.
Download Create a library that consists of VIEWS of another library. Useful for accessing metadata without accessing the data. 4k v. 9 Jun 20, 2011, 5:58 PM Chris S.
Download Import file without delimiting it. 3k v. 5 Feb 16, 2016, 2:36 PM Chris S.
Download Write "issues" (error/warning) to the log when a data set contains records. 2k v. 11 Jul 20, 2011, 7:56 AM Chris S.

References: v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v. 
 v.