Why does it take longer for SAS to create a dataset from a data step view using, for example, sashelp.vcolumn
versus the equivalent SQL table dictionary.columns
?
I did a test using fullstimer
and it seems to confirm my suspicion of performance differences.
option fullstimer;
data test1;
set sashelp.vcolumn;
where libname = 'SASHELP' and
memname = 'CLASS' and
memtype = 'DATA';
run;
proc sql;
create table test2 as
select *
from dictionary.columns
where libname = 'SASHELP' and
memname = 'CLASS' and
memtype = 'DATA';
quit;
An excerpt from the log:
NOTE: There were 5 observations read from the data set SASHELP.VCOLUMN.
WHERE (libname='SASHELP') and (memname='CLASS') and (memtype='DATA');
NOTE: The data set WORK.TEST1 has 5 observations and 18 variables.
NOTE: DATA statement used (Total process time):
real time 0.67 seconds
user cpu time 0.23 seconds
system cpu time 0.23 seconds
memory 3820.75k
OS Memory 24300.00k
Timestamp 04/13/2015 09:42:21 AM
Step Count 5 Switch Count 0
NOTE: Table WORK.TEST2 created, with 5 rows and 18 columns.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.03 seconds
user cpu time 0.01 seconds
system cpu time 0.00 seconds
memory 3267.46k
OS Memory 24300.00k
Timestamp 04/13/2015 09:42:21 AM
Step Count 6 Switch Count 0
The memory used is a little higher for SASHELP but the difference isn't huge. Note the time--it's 22 times longer using SASHELP than with the SQL dictionary. Surely it can't just be due to the relatively small difference in memory usage.
At @Salva's suggestion, I resubmitted the code in a new SAS session, this time running the SQL step before the data step. The memory and time differences are even more pronounced:
| sql | sashelp
----------------+-----------+-----------
real time | 0.28 sec | 1.84 sec
user cpu time | 0.00 sec | 0.25 sec
system cpu time | 0.00 sec | 0.24 sec
memory | 3164.78k | 4139.53k
OS Memory | 10456.00k | 13292.00k
Step Count | 1 | 2
Switch Count | 0 | 0
Some (if not all) of this is the difference in overhead between SQL and Data Step. For example:
Also very fast.
The SAS page about Dictionary Tables gives some information that is likely the main explanation.
In my experience, using the sashelp views is slower than using proc datasets. This is more so if you have a lot of libraries assigned, especially external ones: