Check the number of row in SAS dataset

466 Views Asked by At

I am giving the below command to check the number of rows in SAS data set but it's outputting the 60 records of dataset however the dataset have 247 records.

Is there is any other way to do in unix command?

UNIX command:

awk 'END {print NR}' /home/user/check.sas7bdat

2

There are 2 best solutions below

1
Therkel On

What about just doing it in a SAS datastep? You can fetch the number of rows with the NOBS statement.

/* Test dataset */
data have;
    a = 1;output;
    a = 2;output;
    a = 3;output;
run;


data _null_;
    set have NOBS = size;
    call symput("size",strip(size));
run;

%put NOTE: Number of records: &size.;
NOTE: Number of records: 3
1
DomPazz On

You need to write a SAS program to output the number of observations for you. The structure of the sas7bdat file is complicated.

data _null_;
   file stdout;
   set "&sysparm" nobs=nobs;
   put "NOBS:" nobs;
   stop;
run;

I named this "test.sas"

This reads in the data set specified in a passed system parameter and outputs to STDOUT the number of observations.

I created a test data set in my home directory like:

libname d "~/";

data d.test;
do i=1 to 1000;
   output;
end;
run;

From the command line run

<path to sas>/sas test.sas -sysparm ~/test.sas7bdat

I get NOBS:1000 back.