BookmarkSubscribeRSS Feed
yatinrao
Obsidian | Level 7

I would like to know how many tables are loaded in the memory from a caslib.  I know I can use tableinfo to get list of loaded tables . i want to be able to process the results of tableinfo to save each table in the caslib 

 

I could not find any documentation about the structure of the result set and how to use it. 

Any help would be appreciated .

 

 

1 REPLY 1
SASJedi
SAS Super FREQ

You can get a detailed description of any cas action result set using the describe statement. 

proc cas;
   /* Get a list of all the tables in the CASUSER caslib */
   action table.tableinfo result=r/caslib="casuser";
   /* Write a description of the result set to the SAS log */
   describe r;
quit;

Produces this information in the SAS log:

dictionary ( 1 entries, 1 used);
[TableInfo] Table ( [2] Rows [24] columns
Column Names:
[1] Name [ ] (varchar)
[2] Label [ ] (varchar)
[3] Rows [ ] (int64)
[4] Columns [ ] (int64)
[5] IndexedColumns [Indexed Columns ] (int64)
[6] Encoding [ ] (char)
[7] CreateTimeFormatted [Created ] (varchar)
[8] ModTimeFormatted [Last Modified ] (varchar)
[9] AccessTimeFormatted [Last Accessed ] (varchar)
[10] JavaCharSet [Character Set ] (char)
[11] CreateTime [ ] (double)
[12] ModTime [ ] (double)
[13] AccessTime [ ] (double)
[14] Global [ ] (int32)
[15] Repeated [ ] (int32)
[16] View [ ] (int32)
[17] MultiPart [ ] (int32)
[18] SourceName [Loaded Source ] (varchar)
[19] SourceCaslib [Source Caslib ] (varchar)
[20] Compressed [ ] (int32)
[21] Creator [Table Creator ] (varchar)
[22] Modifier [Last Table Modifier] (varchar)
[23] SourceModTimeFormatted [Source Modified ] (varchar)
[24] SourceModTime [ ] (double)

 

So, the result set is a dictionary with a single entry, a table named TableInfo. In the TableInfo table, the NAME column contains the names of the tables in the caslib. We can use this table to drive other CAS actions. For example:

 

proc cas;
   /* Get a list of all the tables in the CASUSER caslib */
   action table.tableinfo result=r/caslib="casuser";
   /* Using the result set, process every table in a specified caslib */
   do i over r.tableinfo;
      /* Display detailed table information */
      table.tabledetails result=tinfo / caslib="casuser" name=i.name;
      print tinfo;
      /* Display detailed column information */
      table.columninfo result=cinfo / table={caslib="casuser" name=i.name};
      print cinfo;
      /* Display 5 rows  */
      table.fetch / table={caslib="casuser" name=i.name} to=5;
   end;
quit;

Produces the following results:

tinfo: Results from table.tableDetails

 
Detail Information for CARS in Caslib CASUSER(SASJedi).
Node Number
of
Blocks
Active
Blocks
Rows Data size Variable
Data size
Blocks
Mapped
Memory
Mapped
Blocks
Unmapped
Memory
Unmapped
Blocks
Allocated
Memory
Allocated
Index
Size
Compressed
Size
Compression
Ratio
ALL 40 20 428 68480 0 20 72000 20 72000 0 0 0 0 0

cinfo: Results from table.columnInfo

 
Column Information for CARS in Caslib CASUSER(SASJedi)
Column Label Id Type Length Formatted
Length
Format Format
Width
Format
Decimal
Make   1 char 13 13   0 0
Model   2 char 40 40   0 0
Type   3 char 8 8   0 0
Origin   4 char 6 6   0 0
DriveTrain   5 char 5 5   0 0
MSRP   6 double 8 8 DOLLAR 8 0
Invoice   7 double 8 8 DOLLAR 8 0
EngineSize Engine Size (L) 8 double 8 12   0 0
Cylinders   9 double 8 12   0 0
Horsepower   10 double 8 12   0 0
MPG_City MPG (City) 11 double 8 12   0 0
MPG_Highway MPG (Highway) 12 double 8 12   0 0
Weight Weight (LBS) 13 double 8 12   0 0
Wheelbase Wheelbase (IN) 14 double 8 12   0 0
Length Length (IN) 15 double 8 12   0 0

Results from table.fetch

 
Selected Rows from Table CARS
_Index_ Make Model Type Origin DriveTrain MSRP Invoice Engine Size (L) Cylinders Horsepower MPG (City) MPG (Highway) Weight (LBS) Wheelbase (IN) Length (IN)
1 Acura MDX SUV Asia All $36,945 $33,337 3.5 6 265 17 23 4451 106 189
2 Audi RS 6 4dr Sports Europe Front $84,600 $76,417 4.2 8 450 15 22 4024 109 191
3 BMW 745Li 4dr Sedan Europe Rear $73,195 $66,830 4.4 8 325 18 26 4464 123 204
4 Cadillac Seville SLS 4dr Sedan USA Front $47,955 $43,841 4.6 8 275 18 26 3992 112 201
5 Chevrolet Astro Sedan USA All $26,395 $23,954 4.3 6 190 14 17 4605 111 190

tinfo: Results from table.tableDetails

 
Detail Information for IRIS in Caslib CASUSER(SASJedi).
Node Number
of
Blocks
Active
Blocks
Rows Data size Variable
Data size
Blocks
Mapped
Memory
Mapped
Blocks
Unmapped
Memory
Unmapped
Blocks
Allocated
Memory
Allocated
Index
Size
Compressed
Size
Compression
Ratio
ALL 40 20 150 7200 0 20 10720 20 10720 0 0 0 0 0

cinfo: Results from table.columnInfo

 
Column Information for IRIS in Caslib CASUSER(SASJedi)
Column Label Id Type Length Formatted
Length
Format
Width
Format
Decimal
Species Iris Species 1 char 10 10 0 0
SepalLength Sepal Length (mm) 2 double 8 12 0 0
SepalWidth Sepal Width (mm) 3 double 8 12 0 0
PetalLength Petal Length (mm) 4 double 8 12 0 0
PetalWidth Petal Width (mm) 5 double 8 12 0 0

Results from table.fetch

 
Selected Rows from Table IRIS
_Index_ Iris Species Sepal Length (mm) Sepal Width (mm) Petal Length (mm) Petal Width (mm)
1 Setosa 50 33 14 2
2 Setosa 49 30 14 2
3 Setosa 51 35 14 3
4 Versicolor 61 28 40 13
5 Versicolor 58 27 39 12

 

 

You didn't specify how you wanted to save the tables - as files in the CASLIB (and what type - SASHDAT, CSV, etc) or as SAS data sets, so I have no sample code for that. But these same techniques should be able to be adapted for use with the table.save CAS action of the SAVERESULT statement to achieve your desired result.

Hope this helps. May the SAS be with you!

 

Check out my Jedi SAS Tricks for SAS Users

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 528 views
  • 0 likes
  • 2 in conversation