求助:如何恢复SAS日志显示原始代码的功能?
Hey there, let’s figure out why your SAS log stopped showing original code and only displays green/red comments—this is a common quirk with straightforward fixes, so let’s dive in:
1. Force Enable Source Code Display via System Options
The most likely culprit is that the SOURCE and SOURCE2 system options got toggled off (maybe accidentally via a script or setting change). Run these lines at the very start of your program to re-enable them:
OPTIONS SOURCE SOURCE2;
SOURCEcontrols whether your main program code prints in the logSOURCE2handles code pulled in via%INCLUDEstatements
Since you mentioned Richard’s first option didn’t work, double-check that you’re running these options before executing your main code—sometimes timing or conflicting settings can override this if placed later.
2. Adjust GUI Log Display Preferences
If you’re using the SAS desktop GUI (Base SAS or Enterprise Guide), the log’s display settings might be hiding source code:
- Base SAS: Go to
Tools > Options > Preferences, switch to the Log tab, and make sure the "Source" box is checked under "Items to display". - SAS Enterprise Guide: Navigate to
Tools > Options > SAS Programs, then under the "Log" section, ensure "Include source code in log" is selected.
These settings sometimes get reset after SAS updates or profile changes, so it’s worth verifying even if you didn’t tweak them manually.
3. Check for Auto-Execute or Startup Scripts
SAS runs auto-execute scripts (like autoexec.sas) at startup, which might be silently setting OPTIONS NOSOURCE; without you realizing. To check this:
- Run this line to find your SAS root directory:
%PUT %SYSGET(SASROOT); - Look for an
autoexec.sasfile in that directory (or ask your admin if your site uses a custom startup script). - If you see
OPTIONS NOSOURCE;orOPTIONS NOSOURCE2;in the script, comment those lines out with a*at the start.
4. Test with a Minimal Program
If none of the above work, narrow down the issue by running a super simple test program:
OPTIONS SOURCE SOURCE2; DATA test; x = 1; RUN;
If this minimal program shows the DATA test; line in the log, the problem is likely specific to your original program (maybe a rogue OPTIONS NOSOURCE; buried in the code somewhere). Search your program for any NOSOURCE or NOSOURCE2 statements and remove them.
内容的提问来源于stack exchange,提问作者Davide Cortellino

