Skip to content

Instantly share code, notes, and snippets.

@Cesar-Urteaga
Cesar-Urteaga / 160225_MCreateStringRange.sas
Last active January 8, 2018 00:03
Macro function that creates a vector, in fact a string, of variable names concatenated with a suffix.
/*-----------------------------------------------------------------------------|
| Description : Macro function that creates a vector, in fact a string, of |
| variable names concatenated with a suffix (a date or a number, |
| depending on the parameters given). |
| Assumptions : The last character of the "Collapse" parameter is useless in |
| the output string for the last created variable name. |
| Parameters : VariablePrefix - Prefix of the variable of interest. |
| InitialSuffix - Initial date of the period in format YYMM. |
| If you give a numeric character with less |
| than 4 digits, it will create a sequence of |
@Cesar-Urteaga
Cesar-Urteaga / 160622_MCompareDataSets.sas
Created June 22, 2017 23:45
Compares two tables, record by record, based on a list of ID variables.
/*-----------------------------------------------------------------------------|
| Description : Macro that compares two tables, record by record, based on a |
| list of ID variables. |
| Assumptions : Each table has at least one ID variable, and ID variables must |
| have the same name between tables. |
| N.B.: This macro is based on the suggestion made in the |
| excellent book "Carpenter's Guide to Innovative SAS |
| Techniques" by Art Carpenter, pages 198 through 200. |
| Parameters : BaseTable - Is the reference table. |
| ReferenceTable - Corresponds to the table that is expected |
@Cesar-Urteaga
Cesar-Urteaga / 160306_MSplitDataset.sas
Created March 7, 2017 03:57
Split a dataset into smaller tables.
/*-----------------------------------------------------------------------------|
| Description : Macro that split a dataset into smaller datasets. |
| Assumptions : This macro is based on the paper "Splitting a Large SAS Data |
| Set" by John R. Gerlach and Simant Misra. |
| Parameters : InputDataset - Table to be split. It can include the |
| library. |
| NumberOfDatasets - Corresponds to the number of split tables. |
| OutputDatasets - Prefix of the split tables. It can include |
| the library. |
| Output : A set of split tables created from the input table. |
@Cesar-Urteaga
Cesar-Urteaga / 161214_MRenameTableFields.sas
Created March 4, 2017 23:04
Renames the fields of a table based on a string with field names.
/*-----------------------------------------------------------------------------|
| Description : Renames the fields of a table based on a string with field |
| names. |
| Assumptions : Parameters' table names have the library attached. |
| Parameters : InputTable - Table with the original names. |
| OutputTable - Table with the new names (Default: InputTable). |
| OldNames - String with the old names separated by spaces. |
| NewNames - String with the new names separated by spaces. |
| PrefixCharacter - A prefix to be used to define the new names. |
| Output : A new table (or an overwritten one) with the new names. |