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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 866 views
  • 3 likes
  • 2 in conversation