Este artículo explica cómo distinguir una macro variable vacía (nula) de una macro variable que contiene un punto, y cómo realizar estas pruebas correctamente.
Es crucial comprender la naturaleza de su variable:
Macro variable vacía (Nula): No contiene ningún carácter.
Ejemplo: %let maVar = ;
Macro variable que contiene un punto: Contiene el carácter ".". Para el procesador de macros, es una cadena de caracteres de longitud 1, no un valor faltante.
Ejemplo: %let maVar = .;
Si prueba %if &maVar = ., está verificando literalmente si la variable contiene el carácter "punto", y no si está vacía.
Método 1: Usar la función %LENGTH (Recomendado)
El método más robusto para verificar si una macro variable está "vacía" o "nula" es probar su longitud.
Para verificar si una variable está vacía:
%if %length(&maVar) = 0 %then %do;
%put La variable est vide.;
%end;
1
%IF %LENGTH(&maVar) = 0 %THEN %DO;
2
3
%put La variable est vide.;
4
5
%END;
6
Para verificar si una variable contiene un valor (no vacía):
Un punto (.) es un carácter, no un valor faltante en el sentido de macro.
Utilice %if %length(&var) = 0 para probar un valor nulo (vacío).
Para profundizar en el tema de los valores faltantes y lógicos en las macros, los trabajos de Chung y King sobre el tema son referencias técnicas sólidas.
Important Disclaimer
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.