-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnvars.sas
50 lines (36 loc) · 1.55 KB
/
nvars.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
%macro NVars(ds) / des='Number of vars';
/********************************************************************************
BEGIN MACRO HEADER
********************************************************************************
Name: NVars
Author: Chris Swenson
Created: 2010-07-20
Purpose: Output the number of variables in a data set
Arguments: ds - input data set to count variables
Revisions
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Date Author Comments
¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯
YYYY-MM-DD III Please use this format and insert new entries above
********************************************************************************
END MACRO HEADER
********************************************************************************/
/* Check if the table exists */
%if "&ds"="" %then %do;
%put %str(E)RROR: The data set argument is blank.;
%return;
%end;
%if %eval(%sysfunc(exist(&ds, %str(DATA))) + %sysfunc(exist(&ds, %str(VIEW))))=0 %then %do;
%put %str(W)ARNING: %sysfunc(compbl(The &ds data set does not exist)).;
%return;
%end;
/* Manage scope */
%local arg dsid vid rc;
/* Open data set */
%let dsid=%sysfunc(open(&ds));
%let NVars=%sysfunc(attrn(&dsid, NVars));
/* Close data set */
%let rc=%sysfunc(close(&dsid));
/* Output type */
&NVars
%mend NVars;