BookmarkSubscribeRSS Feed
znhnm
Quartz | Level 8

Hi!

I have a few datasteps where I create a new dataset after running. These datasteps  affect the number or rows or columns in my dataset. 

How do  keep the information about number of columns and rows of each dataset so that I can create a graph how may records or columns I added/droped?

 

Thank you!

9 REPLIES 9
LinusH
Tourmaline | Level 20

This information can be obtained from the DICTIONARY.TABLES in PROC SQL, or the corresponding SASHELP.VTABLE view.

For details on columns use DICTIONARY.COLUMNS/SASHELP.VCOLUMN.

Data never sleeps
PeterClemmensen
Tourmaline | Level 20

See if you can use this as a template

 

proc sql;
   create table tableinfo as
   select * from dictionary.tables
   where libname = 'SASHELP'
   ;
quit;
znhnm
Quartz | Level 8
Thanks for the reply! what do I write for the "tables" in line 2? Also, where do I list the relevant tables in my caslib? (I have irrelevant tables in the same caslib)
LinusH
Tourmaline | Level 20

You can start with

proc sql;
   describe dictionary.tables;
quit;

There you can see a columns names MEMNAME (if remember correctly).

So just add that to the where clause:

proc sql;
   create table tableinfo as
   select * from dictionary.tables
   where libname = 'MYCASLIB' and
         memname = 'MYCASTAB'
   ;
quit;
Data never sleeps
s_lassen
Meteorite | Level 14

While learning to use dictionary.tables and dictionary.columns is a very good idea, there are also other ways to do this.

Here is a simple datastep hack, showing how to get the information for SASHELP.CLASS:

data _null_;
  if 0 then set sashelp.class nobs=_nobs;
  array _chars _character_;
  array _nums _numeric_;
  call symputx('columns',dim(_chars)+dim(_nums));
  call symputx('rows',_nobs);
run;

%put &=columns;
%put &=rows;

 

data_null__
Jade | Level 19

Don't forget to STOP;

 

NOTE: DATA STEP stopped due to looping.

Patrick
Opal | Level 21

I haven't had the opportunity yet to really work with Viya/CAS but I believe that all the answers given so far that reference the SAS Dictionary tables are not applicable for CAS tables but only for SAS 9.4 SAS files (I can be wrong). As I understand it working with CAS tables is closer to working with database tables than with SAS 9.4 SAS files.

Running code in SPRE you can eventually use the SAS dictionary tables for getting the list of tables (dictionary.tables) and it's certainly worth to check if the column for number of observations is populated - but I doubt that this will work.

Just based on docu and depending on your environment you need likely to use either Proc CASUTIL, Proc CAS or CASL to retrieve such information.

LinusH
Tourmaline | Level 20

I don't have access to SAS Viya at this point, but I was assuming (maybe incorrectly) that if you have a libref assigned to your caslib, that it contents would show up in the PROC SQL DICTIONARY...?

Data never sleeps
Patrick
Opal | Level 21

@LinusH wrote:

I don't have access to SAS Viya at this point, but I was assuming (maybe incorrectly) that if you have a libref assigned to your caslib, that it contents would show up in the PROC SQL DICTIONARY...?


I also believe it would show the tables but not necessarily a row count - similar to what you'd see if it would be a libref pointing to a database table.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 3172 views
  • 2 likes
  • 6 in conversation