Not go through the dataset, or using sql? Anyway using macro directly by fetching from meta info?!
%let dsid=%sysfunc(open(sashelp.class));
%let nobs=%sysfunc(attrn(&dsid,nlobs));
%let dsid=%sysfunc(close(&dsid));
%put SASHELP.CLASS has &nobs. obs. ;
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.
my SASHELP.VTABLE only shows up info on dataset in sashelp, not in work ...
@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');
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;
this works great. SQL count seems to me it goes count rather than grab from meta info
%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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.