DATA Step, Macro, Functions and more

about OPEN function

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

about OPEN function

Hi SAS team!

My code was like this:


%macro a;

data sample1;

a=1;

run;

data lack;

run;

%let s1=%sysfunc(open(sample1));

%let lk=%sysfunc(open(lack));

%if &s1>0 and &lk>0 %then %do;

      %put &s1 &lk;

  %end;

  %else %do;

      %put "one of the dataset can not be opened";

  %end;

%let rc=%sysfunc(close(&s1));

%let rc=%sysfunc(close(&lk));

%mend a;

%a;

i expected that the note of "one of the dataset can not be opened" were written to the LOG, but the result was "1 2". Would anyone could explain how it happened and demonstrate the usage of OPEN function or other functions if the former note would be written.


Appreciate any help!


Qinly


Accepted Solutions
Solution
‎03-16-2014 10:53 AM
Super User
Super User
Posts: 7,050

Re: about OPEN function

Posted in reply to LinyuanQin

You could try FETCH()

View solution in original post


All Replies
Super User
Super User
Posts: 7,050

Re: about OPEN function

Posted in reply to LinyuanQin

OPEN will return a file handle number. Hence the 1 and 2 that you see in the log.

They should both successfully open the datasets you just created .

Occasional Contributor
Posts: 12

Re: about OPEN function

Thank you, Tom. And if both data sets do exist, but one of them has no obs, just like data set lack, which function could achieve my purpose?

Solution
‎03-16-2014 10:53 AM
Super User
Super User
Posts: 7,050

Re: about OPEN function

Posted in reply to LinyuanQin

You could try FETCH()

Occasional Contributor
Posts: 12

Re: about OPEN function

Thank you, Tom! I've solved it by your suggestion.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 238 views
  • 3 likes
  • 2 in conversation