Often we need to add a prefix to some or all variables in a dataset before we might have to merge datasets that have similar column attributes…This macro would allow you to do that….
When you submit code or a catalog entry from the Enhanced Editor, the filename or catalog entry name and their respective folders are placed in these environment variables:
contains the full path of the submitted program or catalog entry. The full path includes the folder and the filename.
contains only the name of the submitted program or the catalog entry name.
You can then extract the filename and full path for use in your SAS programs.
After the following DATA step runs and the data is sorted, the PRINT procedure includes the filename in the title and the full path in the footnote of the procedure output. The results are shown below as a Screen Shot
Here’s a simple SAS Macro to delete a SAS dataset…It takes the name of the SAS dataset as the parameter…
Here is a macro to quickly cleanup the work directory programmatically… It uses Proc Datasets with KILL option to delete the datasets in the library… The valid values for the parameter memtype are ACCESS ALL CATALOG DATA FDB MDDB PROGRAM VIEW only…
Often a times, we get a dataset with missing values for certain variables…And for reporting purposes we need to convert them some or all of those variable values to default values (for e.g 0 for numeric values or NULL for character values)..
Well…there are many ways of getting the observation count into a macro variable…but there a few pros and cons in those methods…
How do you reorder variables in a dataset…I get this many a times….Here’s a macro for you to achieve it…For example I’ve used a dataset sashelp.flags and created some more variables with variety of variables with names upper / lower cases and _’s to demonstrate the reorder macro….
When you are dealing with macros a lot there would be a need to split a macro variables values to multiple macro variables values and also get the split count into another variable….
Try this macro for those purposes….
Suppose there was a large dataset….This SAS macro program splits the dataset by the number of observations mentioned as a parameter…
Here’s a SAS macro to Create and Remove a PC Directory… Often we ignore Notes and warning in the SAS log when we try to create/remove a directory that does/doesn’t exist…This macro first checks for the existence of the directory and then create/delete it or else put a message to the SAS log…try it out