macro program to display number of variables in a dataset

Reply
Regular Contributor
Posts: 190

macro program to display number of variables in a dataset

macro program to display number of variables in a dataset?

Super User
Super User
Posts: 7,706

Re: macro program to display number of variables in a dataset

proc sql noprint;
  select NVAR
  into    NUM_VARS
  from  DICTIONARY.TABLES
  where  LIBNAME="SASHELP"
      and  MEMNAME="CLASS";
quit;

%put Number of variables = &NUM_VARS.;

Its all in the metadata tables -> SASHELP.VTABLE, VCOLUMN or respectively for SQL DICTIONARY.TABLES, COLUMNS.

Regular Contributor
Posts: 190

Re: macro program to display number of variables in a dataset

proc sql noprint;
select MEMNAME
into :HELLO
from rrt
order by MEMNAME;
quit;


proc contents data=sashelp.class
out= work.rrt noprint;
run; i did same but i can't get the no of variables in d log
Super User
Super User
Posts: 7,706

Re: macro program to display number of variables in a dataset

Please look at the code I have posted in the previous mail, and compare it to what you have posted here.  You will see that you are select dataset name (variable MEMNAME), not the count of variables variable (which is NVAR).

 

In fact, examine the tables presented in the SASHELP library, VTABLE and VCOLUMN, you will then see the metadata of all the tables in SAS.

Regular Contributor
Posts: 190

Re: macro program to display number of variables in a dataset

hello rw9 is num_vars storing the variable number?
Super User
Super User
Posts: 7,706

Re: macro program to display number of variables in a dataset

NUM_VARS is a macro variable.  Macro Variables are always text.  To use is as a number you need to wrap it in an input, e.g

input("&NUM_VARS.",best.);

 

 

Ask a Question
Discussion stats
  • 5 replies
  • 341 views
  • 1 like
  • 2 in conversation