How to Get number of observations and Variables in SAS?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #49431
    rlochan2021
    Keymaster

    1.
    %macro obsnvars(ds);
    %global dset nvars nobs;
    %let dset=&ds;
    %let dsid = %sysfunc(open(&dset));

    %if &dsid %then %do;
    %let nobs =%sysfunc(attrn(&dsid,nlobs));
    %let nvars=%sysfunc(attrn(&dsid,nvars));
    %let rc = %sysfunc(close(&dsid));
    %end;

    %else %put open for data set &dset failed – %sysfunc(sysmsg());
    %mend obsnvars;

    %obsnvars(XYZ)

    %put &dset has &nvars variable(s) and &nobs observation(s).;

    #49432
    rlochan2021
    Keymaster

    PROC SQL;
    select memname, name, length(name) as Variable_Length, label,
    length(label)as label_length
    from dictionary.columns
    where libname=”WORK” and memtype=”DATA”;
    QUIT;

    PROC SQL;
    select memname, name, length(name) as Variable_Length, label,
    length(label)as label_length
    from dictionary.columns
    where libname=”DATADIR” and memtype=”DATA” and
    (length(name)>8 or length(label)=1 or
    length(label)>40);
    QUIT;

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.