如何修改DM命令以打开RWORK库中最后创建的数据集?
How to Modify the DM Command to Open the Latest Dataset in RWORK Library
Great question! The original dm "vt &syslast"; command relies on the &syslast macro variable, which SAS automatically updates to point to the most recently created/modified dataset across all libraries—by default, that often ends up being in the WORK library. To target the latest dataset specifically in the RWORK library, we need to explicitly fetch that dataset instead of relying on the global &syslast.
Here's the reliable, step-by-step solution:
- First, query SAS's built-in metadata to get the name of the newest dataset in RWORK:
proc sql noprint; select memname into :rwork_last trimmed from dictionary.tables where libname = 'RWORK' /* Filter to the RWORK library (case-sensitive!) */ order by crdate desc /* Sort by creation date, newest first */ fetch first 1 row only; /* Grab just the top (newest) dataset */ quit;
- Then use the DM command to open that specific dataset:
dm "vt RWORK.&rwork_last";
Why this works:
dictionary.tablesis SAS's system metadata table that tracks details about every dataset in your session, including its library, name, and creation timestamp.- We narrow down to only RWORK library datasets, sort them by creation date in descending order, and pick the first result to ensure we get the latest one.
- The
trimmedoption removes extra whitespace from the macro variable, preventing errors in the DM command.
If you want a reusable shortcut, wrap this logic into a macro:
%macro open_rwork_last(); proc sql noprint; select memname into :rwork_last trimmed from dictionary.tables where libname = 'RWORK' order by crdate desc fetch first 1 row only; quit; dm "vt RWORK.&rwork_last"; %mend; /* Run this whenever you need to open RWORK's latest dataset */ %open_rwork_last();
内容的提问来源于stack exchange,提问作者sria
相关产品推荐
相关产品推荐

