SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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