DATA Step, Macro, Functions and more

%SYSFUNC open

Reply
New Contributor
Posts: 4

%SYSFUNC open

Hello all, 

 

I used two lines to open a dataset in my macro. 

 

%let dataset=temp;

%let nobs=%sysfunc(attrn(%sysfunc(open(&ds)),NOBS));

 

I used the sysfunc close in order to close, but I learned that my dataset was not closed because I couldn't make changes to the dataset.

 

Can anyone tell me what I can do to close the dataset?

 

Thanks. 

 

Bo klauth

Super Contributor
Posts: 468

Re: %SYSFUNC open

If your trying to get the number of observation in a SAS Dataset then why not query the VTABLE

 


PROC SQL; 
select nobs INTO: nobs 
from sashelp.vtable
where libname="SASHELP" and memname="CLASS"
;
quit;

%PUT "Number of Observetions:&nobs";
Thanks,
Suryakiran
New Contributor
Posts: 4

Re: %SYSFUNC open

Posted in reply to SuryaKiran

Hello Suryakiran, 

 

Thanks for your response. I used the whole thing you wrote. The result was 19. Would I need to chang anything? I have 45 observations in my dataset. 

 

Thanks. 

 

Bo Klauth

Super Contributor
Posts: 468

Re: %SYSFUNC open

SASHELP.VTABLE or DICTIONARY.TABLES are read only tables that contains SAS session information. It contains lot of useful information about tables like column names, format, number of recods...etc. 'nobs' is one peice in it that gives the count on a dataset. 

 

PROC SQL; 
create table test as
select * 
from sashelp.vtable
where libname="SASHELP" and memname="CLASS"
;
quit;

Run this and see what all information it can give. LIBNAME=the library where your table is, memname= you dataset name

Thanks,
Suryakiran
Super User
Posts: 9,574

Re: %SYSFUNC open

Insert your library and dataset name in place of SASHELP and CLASS, respectively (use capitals only).

19 is the number of observations in SASHELP.CLASS.


@Klauth wrote:

Hello Suryakiran, 

 

Thanks for your response. I used the whole thing you wrote. The result was 19. Would I need to chang anything? I have 45 observations in my dataset. 

 

Thanks. 

 

Bo Klauth


 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
PROC Star
Posts: 1,327

Re: %SYSFUNC open

[ Edited ]

have you tried to close with proc iml close statement? just a random crazy thought of mine

 

proc iml;

close yourdataset;  

 hmm , by any chance an admin related issue after all? Smiley Sad

Respected Advisor
Posts: 3,832

Re: %SYSFUNC open


@Klauth wrote:

Hello all, 

 

I used two lines to open a dataset in my macro. 

 

%let dataset=temp;

%let nobs=%sysfunc(attrn(%sysfunc(open(&ds)),NOBS));

 

I used the sysfunc close in order to close, but I learned that my dataset was not closed because I couldn't make changes to the dataset.

 

Can anyone tell me what I can do to close the dataset?

 

Thanks. 

 

Bo klauth


Why do you need to know the number of observations?  What do you do with the number? 

Super User
Posts: 13,046

Re: %SYSFUNC open


@Klauth wrote:

Hello all, 

 

I used two lines to open a dataset in my macro. 

 

%let dataset=temp;

%let nobs=%sysfunc(attrn(%sysfunc(open(&ds)),NOBS));

 

I used the sysfunc close in order to close, but I learned that my dataset was not closed because I couldn't make changes to the dataset.

 

Can anyone tell me what I can do to close the dataset?

 

Thanks. 

 

Bo klauth


You have to have the identifier of which file that has been opened you want to close. You do not show how you attempted to close it.

 

Instead of nesting function calls opening the dataset you are likely better off to use something like:

%let dsid  = %sysfunc(open(&ds, i));

%let nobs = %sysfunc(attrn(&dsid));

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

 

 

 

 

Ask a Question
Discussion stats
  • 7 replies
  • 149 views
  • 2 likes
  • 6 in conversation