Hi,
why does SAS return a zero, meaning the dataset does not exist, even though it exists!
%PUT ***** %sysfunc(exist(SASHELP.CLASS , 'ACCESS'));
%PUT ***** %sysfunc(exist(SASHELP.CLASS, 'CATALOG'));
%PUT ***** %sysfunc(exist(SASHELP.CLASS, 'VIEW'));
%PUT ***** %sysfunc(exist(SASHELP.CLASS, 'DATA'));
%PUT ***** %sysfunc(exist(SASHELP.CLASS, "DATA"));
%PUT ***** %sysfunc(exist(SASHELP.CLASS, ));
result in the Log:
19 %PUT ***** %sysfunc(exist(SASHELP.CLASS , 'ACCESS'));
***** 0
20
21 %PUT ***** %sysfunc(exist(SASHELP.CLASS, 'CATALOG'));
***** 0
22
23 %PUT ***** %sysfunc(exist(SASHELP.CLASS, 'VIEW'));
***** 0
24
25 %PUT ***** %sysfunc(exist(SASHELP.CLASS, 'DATA'));
***** 0
26
27 %PUT ***** %sysfunc(exist(SASHELP.CLASS, "DATA"));
***** 0
28
29 %PUT ***** %sysfunc(exist(SASHELP.CLASS, ));
***** 1
The exist documentation tells me, that I can use the optional "member-type" argument. By default it is "DATA".
However, when explicitly using "DATA" or 'DATA' as the optional member-type argument, the function returns the wrong value, i.e. "0"!
Only, when I do not enclose the word DATA in quotes, it returns the correct value:
%PUT ***** %sysfunc(exist(SASHELP.CLASS, DATA ));
29 %PUT ***** %sysfunc(exist(SASHELP.CLASS, DATA ));
***** 1
Am I the only one who gets a littlbe bit confused by this behaviour?
This has nothing to do with the EXIST function. It is a "feature" of %SYSFUNC, where arguments to the function inside %SYSFUNC must not be enclosed in quotes (although if you used the same function without %SYSFUNC inside a data step, quotes are required around character values). This is a global condition (as far as I know) in %SYSFUNC, meaning that ANY function inside of %SYSFUNC should not have quotes around the arguments.
Similar example with INTNX, works with no quotes around the arguments, but produces an error with quotes around the arguments.
%let today=%sysfunc(today());
%put %sysfunc(intnx(month,&today,1,b));
%put %sysfunc(intnx('month',&today,1,'b'));
This has nothing to do with the EXIST function. It is a "feature" of %SYSFUNC, where arguments to the function inside %SYSFUNC must not be enclosed in quotes (although if you used the same function without %SYSFUNC inside a data step, quotes are required around character values). This is a global condition (as far as I know) in %SYSFUNC, meaning that ANY function inside of %SYSFUNC should not have quotes around the arguments.
Similar example with INTNX, works with no quotes around the arguments, but produces an error with quotes around the arguments.
%let today=%sysfunc(today());
%put %sysfunc(intnx(month,&today,1,b));
%put %sysfunc(intnx('month',&today,1,'b'));
HI @FK1
This is natural behaviour of the SAS macro language. When you write code in macro language there is _only_ one data type: text. Everything in macro language is a text so no "quotes" are needed. Starting with PUT statement, in 4GL you are writing:
put "My text to be displayed";
and in macro language you just do:
%put My text to be displayed;
This behaviour is extending for "%sysfunc-ed" functions arguments too.
Here is a bit from documentation:
All the best
Bart
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.