BookmarkSubscribeRSS Feed
HuggyBob
Calcite | Level 5

I am aware of the automatic macro variables SYSNOBS and SQLOBS, which tell me how many observations in a new table, but we do not seem to have one for number of variables. DICTIONARY.TABLES gives me NVAR, which tells me what I want, but I am surprised that we do not have a corresponding macro variable such as SYSNVAR.

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, wasn't aware of these ones, I have always queried the metadata tables.  I suppose its because you should know the structure of your data, as knowing how many variables doesn't help much, I mean you can't really use that info.  However I like the idea, and it is part of the wider discussion on how to access the metadata of the system.  Personally I don't like the macro variable way of doing things.  In my way of thinking metadata should be accessible via a function, which can then be used directly in code explicitly on any dataset not just the last one, maybe something like:

metadata(library=work,member=,property=[,where=]);

 

So you could use it:

number_of_observations=metadata(library=sashelp,member=cars,property=nobs);

number_of_variables=metadata(library=sashelp,member=cars,property=nvar);

Maybe you want to create an array for all col variables:

array list_col{*} metadata(library=sashelp,member=cars,property=vars,where=%str(substr(varname,1,3)="COL"));

 

So a function that can return any of the metadata, not just obs, vars, but any property from table or columns.

 

Reeza
Super User
SAS has a semiformal method for making suggestions, you can post a new idea in the SAS ballotware section so others can vote on the idea.

https://communities.sas.com/t5/SASware-Ballot-Ideas/idb-p/sas_ideas
JoshB
Quartz | Level 8

Something you are probably aware of, but maybe others are not.

 

I've always used sysfunc/qsysfunc with attrn or attrc functions to get to these metadata entries if I want to use functions or store things into macro variables. i.e., for the task at hand for number of variables.

 

%let rc = %sysfunc(open(WORK.HAVE));
%let nvars = %sysfunc(attrn(&rc.,nvars));
%let rc = %sysfunc(close(WORK.HAVE));

%put &nvars.;

 

 The nice thing about these is they can be used in open code or in macros (in my experience).

 

 

Other available attributes are viewable here

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, I quite agree.  The only thing I would say is that the need to do an close(open(function)) syntax is not ideal.  We should be able to pull metadata items using one simple function, which doesn't require opening/closing files, but just returns a query of the metdata tables.

JoshB
Quartz | Level 8
Definitely true. Speaking of, I should probably add that to the end in case someone uses it and doesn't know to close.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 867 views
  • 2 likes
  • 4 in conversation