BookmarkSubscribeRSS Feed
RTelang
Fluorite | Level 6

macro program to display number of variables in a dataset?

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26
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.

RTelang
Fluorite | Level 6
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
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

RTelang
Fluorite | Level 6
hello rw9 is num_vars storing the variable number?
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.);

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 649 views
  • 1 like
  • 2 in conversation