I created an audit trail on my table. However, when I altered my table by adding a new column, its audit trail was removed as well. Is there a way to prevent this from happening or audit trail doesn't work when a table is altered?
From documentation on audit trails
Preservation by Other Operations
The audit trail is not recommended for data files that are copied, moved, sorted in place, replaced, or transferred to another operating environment. Those operations do not preserve the audit trail. In a Copy operation on the same host, you can preserve the data file and audit trail by renaming them using the generation data sets feature. However, logging stops because neither the auditing process nor the generation data sets feature saves the source program that caused the replacement. For more information about generation data sets,
A key word I highlight above is REPLACE. The way SAS manages data once a data set is created then anything that adds a variable replaces the data step.
It might help to describe why you are adding variables to a data set that needs auditing.
If the reason was something like "didn't know I needed it" you have a live and learn moment.
If the reason is following the often dubious spread sheet approach of adding a separate column for every year/month/week or every level of a product then the data design is just plain wrong, especially for audit purposes, and you would be better off having a variable to hold the "type" of value.
instead of
Store JanSalesTotal FebSalesTotal MarSalesTotal <etc>
better would be
Store SalesMonth Total
where SalesMonth would take values like Jan Feb Mar, which are currently data in the title of the variable.
)best would likely be to store that Month as an actual SAS date such as the first or last day of the reporting month)
You might also look at the SASHELP.CARS data set for a product type example. Instead of having separate values for Sedan, SUV, Pickup or such and a separate price, engine size, horsepower column fore each type of car you have the type as a variable.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.