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!
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.
See if you can use this as a template
proc sql;
create table tableinfo as
select * from dictionary.tables
where libname = 'SASHELP'
;
quit;
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;
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;
Don't forget to STOP;
NOTE: DATA STEP stopped due to looping.
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.
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...?
@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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.