BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
In a library if there are 10 datasets and I would like to get the total number of observations from all the 10. is there any way other than using the proc sql and giving the each dataset name?
5 REPLIES 5
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello SASPhile,

This is my solution:
[pre]
proc SQL noprint;
select COUNT(distinct memname) as N into :N
from SASHELP.VMEMBER where libname="WORK" and memtype="DATA";
%let N=%TRIM(&N);
select distinct memname as name into :N1-:N&N
from SASHELP.VMEMBER where libname="WORK" and memtype="DATA";
quit;
%macro a;
%local i obs;
%global nobs;
%do i=1 %to &N;
proc SQL noprint;
select COUNT(*) as obs into :obs from &&n&i
;quit;
%if &i = 1 %then %let nobs=&obs;
%let nobs=%EVAL(&nobs+&obs);
%end;
%mend;
%a;
%put nobs=&nobs;
[/pre]
Sincerely,
SPR
SASPhile
Quartz | Level 8
SPR,
will this display the datasetname and count ?
SPR
Quartz | Level 8 SPR
Quartz | Level 8
This displays name and count:
[pre]
%macro a;
%local i obs;
%do i=1 %to &N;
proc SQL noprint;
select COUNT(*) as obs into :obs from &&n&i
;quit;
%put DATASET=&&n&i obs=%TRIM(&obs);
%end;
%mend;
options nonotes;
%a
oprions notes;
[/pre]
SPR
SASJedi
SAS Super FREQ
Try something like this (replace the SASHELP libref with your libref of interest - make sure you type the libref in all caps):

proc sql;
title 'Total Observations for all datasets in the SASHELP library';
select sum(nlobs) 'Total Observations' format=comma16. as TotObs
from dictionary.tables
where libname ='SASHELP'
and MEMTYPE='DATA'
;
title 'Observations for each dataset in the SASHELP library';
select MEMNAME 'Dataset', sum(nlobs) 'Obs' format=comma16. as Obs
from dictionary.tables
where libname ='SASHELP'
and MEMTYPE='DATA'
group by MEMNAME
;
quit;
Check out my Jedi SAS Tricks for SAS Users
Ksharp
Super User
[pre]
proc contents data=work._all_ out=sum(keep=memname nobs);
run;
data want(drop=total);
set sum end=last;
total+nobs;
output;
if last then do;
memname='Total';
nobs=total;
output;
end;
run;
[/pre]
Ksharp

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 826 views
  • 0 likes
  • 4 in conversation