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.
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.
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.);
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.