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

HI all,

I have a dataset a_counts, If it has 0 observations, I have to skip a few steps. 

/*Open dataset*/

myDS=%sysfunc(open(a_counts,i));

/*Get number of observations*/
iswhere=%sysfunc(attrn(&myDS,nobs));

*/DO a few steps if there is data*/
&ISWHERE ne 0 %then %do;

     ----

     ----

     ----

%end;

But this is giving me the following error:

You cannot open WORK.A_COUNTS.DATA for output access with member-level control because WORK.A_COUNTS.DATA is in use by you in resource environment DMS Process.

Please advise.

Thanks,

Archana

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Another way to get the same info without opening (and possibly forgetting to close a data set):

proc sql noprint;

   select nobs into : iswhere

   from dictionary.tables

   where libname='WORK' and memname='A_COUNTS';

quit;

Note that the Libname and Memname must be in upper case OR use the upcase function on the literal value.

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

You have somehow opened this dataset previously in your SAS session. You either need to close this dataset for your code to work, or close SAS and restart SAS.

--
Paige Miller
ballardw
Super User

Another way to get the same info without opening (and possibly forgetting to close a data set):

proc sql noprint;

   select nobs into : iswhere

   from dictionary.tables

   where libname='WORK' and memname='A_COUNTS';

quit;

Note that the Libname and Memname must be in upper case OR use the upcase function on the literal value.

Kurt_Bremser
Super User

You most probably have the dataset opened in a file window. Close that first.

Another method for obtaining the record count:

data _null_;

call symput('lastobs',put(lastobs,best.));

set a_counts nobs=lastobs;

run;

Now &lastobs will hold the number of observations in your dataset. Note the ordering of statements in the data step, which is crucial for it to work when the dataset has zero observations.

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
  • 3 replies
  • 6727 views
  • 8 likes
  • 4 in conversation