Aquí están los diferentes métodos para recuperar esta información, ya sea para crear macrovariables o para usarla directamente en el código.
Note : 1. Obtener la fecha de hoy (TODAY)
Para obtener la fecha actual, utilice la función today().
Opción A: Crear una macrovariable (valor bruto) Esto almacena la fecha como un número (el número de días desde el 01/01/1960). Útil para cálculos.
%let today_raw = %sysfunc(today());
/* Résultat exemple : 23456 */
1
%let today_raw = %sysfunc(today());
2
3
/* Résultat exemple : 23456 */
Note : Opción B: Crear una macrovariable (formateada) Si necesitas una fecha legible (por ejemplo, para el título de un informe o un nombre de archivo), añade un formato como segundo argumento en %sysfunc.
Note : Opción C: Uso directo en un paso Data o PROC SQL No necesitas una macrovariable si ya estás dentro de un paso Data.
data _null_;
current_date = today();
put current_date date9.;
run;
1
DATA _null_;
2
current_date = today();
3
put current_date date9.;
4
RUN;
Note : Obtener la hora y la fecha completa (DATETIME)
Si necesitas más precisión (la hora exacta o la marca de tiempo completa), la lógica es la misma.
The codes and examples provided on WeAreCAS.eu are for educational purposes. It is imperative not to blindly copy-paste them into your production environments. The best approach is to understand the logic before applying it. We strongly recommend testing these scripts in a test environment (Sandbox/Dev). WeAreCAS accepts no responsibility for any impact or data loss on your systems.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.