BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
FK1
Lapis Lazuli | Level 10 FK1
Lapis Lazuli | Level 10

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?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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'));

 

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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'));

 

--
Paige Miller
yabwon
Onyx | Level 15

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:

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1o13d7wb2zfcnn19s5ssl2zdxvi.htm#p19...

 

All the best

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Ksharp
Super User
If you use Data Step, you would get right answer. Macro is a TEXT processed language, therefore there is no need quote around DATA .



data _null_;
x=exist("SASHELP.CLASS", "DATA");
put x=;
run;
FK1
Lapis Lazuli | Level 10 FK1
Lapis Lazuli | Level 10

@Ksharp @PaigeMiller @yabwon 

thank you all for your contributions. Now, I understand the issue!

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 596 views
  • 0 likes
  • 4 in conversation