BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LinyuanQin
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You could try FETCH()

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

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 .

LinyuanQin
Calcite | Level 5

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?

Tom
Super User Tom
Super User

You could try FETCH()

LinyuanQin
Calcite | Level 5

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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