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

Not go through the dataset, or using sql?  Anyway using macro directly by fetching from meta info?! 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
%let dsid=%sysfunc(open(sashelp.class));
%let nobs=%sysfunc(attrn(&dsid,nlobs));
%let dsid=%sysfunc(close(&dsid));

%put SASHELP.CLASS has &nobs. obs. ;

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

Using DICTIONARY.TABLES in PROC SQL does exactly that, it reads the dataset metadata from the dataset header page.

If you need the number for processing outside of SQL, you can use SASHELP.VTABLE, which is a SQL view of DiCTIONARY.TABLES.

hellohere
Pyrite | Level 9

my SASHELP.VTABLE only shows up info on dataset in sashelp, not in work ...

Kurt_Bremser
Super User

@hellohere wrote:

my SASHELP.VTABLE only shows up info on dataset in sashelp, not in work ...



SASHELP.VTABLE has metadata for ALL datasets in currently assigned libraries, which includes WORK:

data class;
set sashelp.class;
run;

data _null_;
set sashelp.vtable;
where libname ="WORK" and memname = "CLASS";
put nobs=;
run;

Log:

 69         data class;
 70         set sashelp.class;
 71         run;
 
 NOTE: There were 19 observations read from the data set SASHELP.CLASS.
 NOTE: The data set WORK.CLASS has 19 observations and 5 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              827.78k
       OS Memory           24228.00k
       Timestamp           28.02.2022 01:56:05 nachm.
       Step Count                        24  Switch Count  2
       Page Faults                       0
       Page Reclaims                     183
       Page Swaps                        0
       Voluntary Context Switches        11
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           264
       
 
 72         
 73         data _null_;
 74         set sashelp.vtable;
 75         where libname ="WORK" and memname = "CLASS";
 76         put nobs=;
 77         run;
 
 nobs=19
 NOTE: There were 1 observations read from the data set SASHELP.VTABLE.
       WHERE (libname='WORK') and (memname='CLASS');
Patrick
Opal | Level 21

hello there

What's wrong with SQL querying dictionary tables (=NOT a select count(*) ). Anyhow here one way without SQL.

data _null_;
  call symputx('n_obs',nobs);
  stop;
  set sashelp.class nobs=nobs;
run;

%put &=n_obs;

 

hellohere
Pyrite | Level 9

this works great. SQL count seems to me it goes count rather than grab from meta info 

Ksharp
Super User
%let dsid=%sysfunc(open(sashelp.class));
%let nobs=%sysfunc(attrn(&dsid,nlobs));
%let dsid=%sysfunc(close(&dsid));

%put SASHELP.CLASS has &nobs. obs. ;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 3521 views
  • 7 likes
  • 4 in conversation