BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
changxuosu
Quartz | Level 8

Dear SAS community,

 

I have a question that needs your wisdom.

 

I have 30 tables, say Table1,table2,...table 30. All of them have the same data structure and the same list of variables except that the ith  table denotes the month i.

 

Now I need to create a new table X, which is composed of two columns/variables.

 

The first variable of table X is i, the index for table i; the second variable of table X is the number of observations for table i.

 

Does any one can point me to any idea/procedure/SAS macro that achieve this?

 

Thanks in advance!!!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@changxuosu wrote:

Dear SAS community,

 

I have a question that needs your wisdom.

 

I have 30 tables, say Table1,table2,...table 30. All of them have the same data structure and the same list of variables except that the ith  table denotes the month i.

 

Now I need to create a new table X, which is composed of two columns/variables.

 

The first variable of table X is i, the index for table i; the second variable of table X is the number of observations for table i.

 

Does any one can point me to any idea/procedure/SAS macro that achieve this?

 

Thanks in advance!!!

 

 

 


By index do you mean the 1, 2, 3 etc that are suffixes to your table name? Or something related to a data set index?

You can find a lot of information about table, including observations with something similar to

proc sql;
   create table x as
   select *
   from dictionary.tables
   where libname='WORK' and memname like ('TABLE%')
   ;
run;

The libname and memname values in the dictionary tables is stored in all upper case.

 

If your names are as simple as you indicate and you want the suffix value then you can get that by

proc sql;
   create table x as
   select substr(memname,6),nobs
   from dictionary.tables
   where libname='WORK' and memname like ('TABLE%')
   ;
run;

Obviously you want to reference the library your data sets exist in.

 

View solution in original post

4 REPLIES 4
Reeza
Super User

SASHELP.VTABLE is a table in SAS with metadata about the tables, you just need to filter it for the tables of interest. I would recommend opening the table first (sashelp.vtable) and looking at it, and then customizing your query. 

 

proc sql;
create table myData as
select libname, memname, nobs
from sashelp.vtable
where upcase(memname) like 'TABLE%';
quit;

SASHELP.VCOLUMN has data about each variable in a data set. 

ballardw
Super User

@changxuosu wrote:

Dear SAS community,

 

I have a question that needs your wisdom.

 

I have 30 tables, say Table1,table2,...table 30. All of them have the same data structure and the same list of variables except that the ith  table denotes the month i.

 

Now I need to create a new table X, which is composed of two columns/variables.

 

The first variable of table X is i, the index for table i; the second variable of table X is the number of observations for table i.

 

Does any one can point me to any idea/procedure/SAS macro that achieve this?

 

Thanks in advance!!!

 

 

 


By index do you mean the 1, 2, 3 etc that are suffixes to your table name? Or something related to a data set index?

You can find a lot of information about table, including observations with something similar to

proc sql;
   create table x as
   select *
   from dictionary.tables
   where libname='WORK' and memname like ('TABLE%')
   ;
run;

The libname and memname values in the dictionary tables is stored in all upper case.

 

If your names are as simple as you indicate and you want the suffix value then you can get that by

proc sql;
   create table x as
   select substr(memname,6),nobs
   from dictionary.tables
   where libname='WORK' and memname like ('TABLE%')
   ;
run;

Obviously you want to reference the library your data sets exist in.

 

changxuosu
Quartz | Level 8
thank you so much, ballardw, it works perfect

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 904 views
  • 5 likes
  • 4 in conversation