As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

Macro nobs

From sasCommunity
Revision as of 11:53, 5 April 2007 by Rjf2 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
/*       Name:             Copyright (C) 2007 Ronald J. Fehd

Boilerplate  : This package is free software;

               you can redistribute it and/or modify it
               under the terms of the
               GNU General Public License (GPL)
               as published by the Free Software Foundation.
               This program is distributed in the hope
               that it will be useful, but WITHOUT ANY WARRANTY;
               without even the implied warranty
               of MERCHANTABILITY
               See the GNU General Public License for more details

Requirements  : description  : given a data set

                              returns the number of observations
               purpose      : provide function

Contexts  : program group: development

               program  type: subroutine
               SAS      type: macro, function
               uses routines: none

Specifications: input  : required: data set name

                        optional: name of attribute: in (nobs, nlobs)
               process: check for errors
                        check for exist(data set)
                        open  data set, get attribute
                        return value
               output : value

Usage Examples: in open code: %Let Data = sashelp.class; title "data: &Data. nobs: %nobs(data = &Data.)";

see test data for macro array in macro to provide dimension of macro array macro parameter: data = %let DimXyz = %nobs(data = &Data.); %do I = 1 to &DimXyz;

   %local       Xyz&I.;

%Array(Name = Xyz

     ,Data = &Data.
     ,Var  = <Var-Name>);

Information  : author: Ronald J. Fehd

                  Centers for Disease Control

keywords: attribute, function, macro, nlobs, nobs, scl functions

      • .................................... */

%MACRO nobs(Data =

          ,Nobs    = nobs /* or nlobs */
          ,Testing = 0
          ) / des  =

'site: macro function returns Nobs of data set'

/* except dictionary.??? */
/* ** store source /* */
/* 3/21/2007 RJF2

NOTE: see attrn(...,NLOBS)

     obs not marked for deletion

Error: NOBS: not exists: dictionary.<???> todo: test sashelp.v???

                                                                                • */

%let Testing = %eval( &Testing.

                    or (    %sysfunc(getoption(ECHOAUTO)) NE ECHOAUTO
                        and %sysfunc(getoption(MPRINT)  ) eq MPRINT
                        and %sysfunc(getoption(SOURCE2) ) eq SOURCE2
                        and %sysfunc(getoption(VERBOSE) ) eq VERBOSE));

%Let Nobs = %lowcase(&Nobs); %if not( "&Nobs" eq "nobs"

       or "&Nobs" eq "nlobs") %then %do;
   %put Err%str()or: %SysMacroName Nobs must be in (nobs,nlobs);
   %goto ReturnNobs;

%local Value; %let Value = .; %if %index(&Data.,.) %then %do;

   %let Libref = %lowcase(%scan(&Data.,1,.));
   %if "&Libref." eq "dictionary" %then
       %put Err%str()or: &SysMacroname.: libref cannot be &Libref.;
   %goto ReturnNobs;

%if not(%sysfunc(exist(&Data.))) %then %do;

   %put &SysMacroname.:not exists: &Data.;
   %goto ReturnNobs;

%local dsid rc; %let dsid = %sysfunc( open(&Data. )); %let Value = %sysfunc(attrn(&dsid.,&Nobs.)); %let rc = %sysfunc(close(&dsid. )); %if &Testing. %then %put _local_; %ReturnNobs:&Value.%Mend Nobs;