Published on :
Macro EXTERNE

Get the last modification date of a dataset

This code is also available in: Deutsch Español Français
This functional macro returns the date and time of the last modification for a specified dataset. It serves as an interface to the '%attrn' macro to retrieve the 'MODTE' attribute. The user has the option to provide a SAS© format for the output. The code manages the distinction between simple date formats (e.g., DATE9.) and datetime formats (e.g., DATETIME20.) to apply the appropriate conversion using DATEPART if necessary.
Data Analysis

Type : EXTERNE


The macro neither creates nor uses specific data. It operates on the metadata of a dataset whose name is passed as a parameter by the user.

1 Code Block
MACRO
Explanation :
Definition of the 'modte' macro with two parameters: 'ds' for the dataset name and 'format' for the output format. The macro first retrieves the numeric value of the modification date via the call to '%attrn'. Then, it checks if a format has been specified. If so, it applies formatting using %SYSFUNC(PUTN), distinguishing between DATE type formats (which require a call to %SYSFUNC(DATEPART)) from others. If no format is provided, the raw numeric value is returned.
Copied!
1%macro modte(ds,FORMAT);
2 %local modte;
3 %let modte=%attrn(&ds,modte);
4 %IF %LENGTH(&FORMAT) %THEN %DO;
5 %IF %index(%upcase(&FORMAT),DATE)
6 and not %index(%upcase(&FORMAT),DATETIME) %THEN %DO;
7%sysfunc(putn(%sysfunc(datepart(&modte)),&FORMAT))
8 %END;
9 %ELSE %DO;
10%sysfunc(putn(&modte,&FORMAT))
11 %END;
12 %END;
13 %ELSE %DO;
14&modte
15 %END;
16%mend modte;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : This is public domain software. No guarantee as to suitability or accuracy is given or implied. User uses this code entirely at their own risk.