Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count Number Of Records from Properties 2

Status
Not open for further replies.

tubbsy123

Programmer
Dec 2, 2004
19
AU
Hi,

I have some very large datasets (roughly 35 million records in each) and need to count the number of records present within them and store it as a macro variable.

I currently use either proc sql or proc freq to do this. This takes a long time run.

Is it possible to take the rows value in the properties window relating to the particular table instead of manually calculating this within my process?

Any help would be greatly received.

Regards

Tubbsy123
 
Macro function

Code:
%macro obsnvars(ds);
       %global dset nvars nobs;
       %let dset=&ds;
	   %let nvars = 0;
	   %let nobs  = 0;
       %let dsid = %sysfunc(open(&dset));
       %if &dsid %then   %do;
           %let nobs =%sysfunc(attrn(&dsid,nobs));
           %let nvars=%sysfunc(attrn(&dsid,nvars));
           %let rc = %sysfunc(close(&dsid));
           %end;
       %else   %do;
           %put open for data set &dset failed - %sysfunc(sysmsg());
   	       %let nobs = -9999999;
           %end;
	   %Put ;
       %Put &dset has &nobs observation(s) and &nvars variable(s).;
%mend obsnvars;

To call:

Code:
%obsnvars(EXTRACT.data1);

&nobs is the macro variable.
 
Mdieckman's method is quicker, as that function reports the number from SAS's header info. If you want a more accurate count you must run through all 35 million records (using the NLOBSF option in the ATTRN function.

In short that method works. I use just three lines of that macro.

Code:
%let dsid  =%sysfunc(open(datasetname)); 
%let myobs =%sysfunc(attrn(&dsid,nobs));
%let dsid  = %sysfunc(close(&dsid));


There are problems with this code. It will return the count on file. Meaning if some transaction caused an observation to be deleted it could return an incorrect count.

Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top