BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MaryA_Marion
Lapis Lazuli | Level 10

The following code runs by itself correctly but when put at end of an autoexec gives no errors and no output. What is wrong with it?

Does an autoexec need special code at end?

 

data timetrak; time1=time(); date=date(); run;                    
data timetrak; set timetrak; file print;
put "STAT 755 Clinical Trials" // 
    "Today's date is " date mmddyy8.  " and the time is" time1 hhmm6. // 
    "Author: Mary A. Marion" /; 
run; quit;

 Thank you. MM 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Does the data set Timetrak exist in the Work library when this code "doesn't run"? If the set is there likely you have something very interesting going on and a Log entry from when it does not run will be needed.

 

Hint: you can simplify that to

data timetrak; 
   time1=time(); 
   date=date();                   
   file print;
   put "STAT 755 Clinical Trials" // 
    "Today's date is " date mmddyy8.  " and the time is" time1 hhmm6. // 
    "Author: Mary A. Marion" /; 
run; 

and if you don't actually need to use the data set Timetrak for anything else you can use Data _null_;

 

FWIW, I have had a somewhat similar data step in my Autoexec for more than 8 years and several versions of SAS that displays a countdown to a given date. I have never had it not run or fail to display the result.

View solution in original post

11 REPLIES 11
ChrisNZ
Tourmaline | Level 20

Do you get a warning that no ODS destination is active?

Where do you expect the text to appear?

Do you see that the code has been run?

Note that your code can be written as:

data _null_;
  TIME=time(); 
  DATE=date(); 
  file print;
  put "STAT 755 Clinical Trials" // 
      "Today's date is " DATE mmddyy8. " and the time is" TIME hhmm6. // 
      "Author: Mary A. Marion" /; 
run; 
MaryA_Marion
Lapis Lazuli | Level 10

No warnings about the ODS destination.
I do have the following lines of code in the AUTOEXEC. I wasn't sure how to refer to the SAS work library. The following is not giving an error however.

106 *ODS GRAPHICS;
107 %let
107 ! sasworklocation="/saswork/SAS_workB81000013419_odaws01-usw2.oda.sas.
107 ! com/SAS_workDB5300013419_odaws01-usw2.oda.sas.com";
108 ods listing gpath=&sasworklocation;
SYMBOLGEN: Macro variable SASWORKLOCATION resolves to
"/saswork/SAS_workB81000013419_odaws01-usw2.oda.sas.com/SAS_workDB5
300013419_odaws01-usw2.oda.sas.com"
109
110 *EMF FILE CREATION IN SAS 9.4;
111 %let workdir=%trim(%sysfunc(pathname(work)));
MLOGIC(TRIM): Beginning execution.
MLOGIC(TRIM): This macro was compiled from the autocall file
/pbr/sfw/sas/940/SASFoundation/9.4/sasautos/trim.sas
MLOGIC(TRIM): Parameter VALUE has value
/saswork/SAS_work0B880000230E_odaws03-usw2.oda.sas.com/SAS_work2C9D000023
0E_odaws03-usw2.oda.sas.com
MLOGIC(TRIM): %LOCAL I
SYMBOLGEN: Macro variable VALUE resolves to
/saswork/SAS_work0B880000230E_odaws03-usw2.oda.sas.com/SAS_work2C9D
0000230E_odaws03-usw2.oda.sas.com
MLOGIC(TRIM): %DO loop beginning; index variable I; start value is 100; stop
value is 1; by value is -1.
SYMBOLGEN: Macro variable VALUE resolves to
/saswork/SAS_work0B880000230E_odaws03-usw2.oda.sas.com/SAS_work2C9D
0000230E_odaws03-usw2.oda.sas.com
SYMBOLGEN: Macro variable I resolves to 100
MLOGIC(TRIM): %IF condition %qsubstr(&value,&i,1) ne is TRUE
MLOGIC(TRIM): %GOTO TRIMMED (label resolves to TRIMMED).
SYMBOLGEN: Macro variable I resolves to 100
MLOGIC(TRIM): %IF condition &i>0 is TRUE
SYMBOLGEN: Macro variable VALUE resolves to
/saswork/SAS_work0B880000230E_odaws03-usw2.oda.sas.com/SAS_work2C9D
0000230E_odaws03-usw2.oda.sas.com
SYMBOLGEN: Macro variable I resolves to 100
MLOGIC(TRIM): Ending execution.
112 data _null_;
SYMBOLGEN: Macro variable WORKDIR resolves to
/saswork/SAS_work0B880000230E_odaws03-usw2.oda.sas.com/SAS_work2C9D
0000230E_odaws03-usw2.oda.sas.com
113 file "&workdir./emf94.sasxreg";
114 put '[CORE\PRINTING\PRINTERS\EMF\ADVANCED]';
115 put '"Description"="Enhanced Metafile Format"';
116 put '"Metafile Type"="EMF"';
117 put '"Vector Alpha"=int:0';
118 put '"Image 32"=int:1';
119 run;
NOTE: The file
"/saswork/SAS_ ...

This may be the problem. How to refer to SAS work location?

PaigeMiller
Diamond | Level 26

A young colleague of mine had a problem where the AUTOEXEC would sometimes not execute.

 

After watching her open SAS and do some work, it was obvious what the problem was.

 

When she double-clicked on the SAS icon on her desktop (which was customized to use a specific autoexec), everything was fine, the autoexec ran. But sometimes she opened SAS by (in Windows) double-clicking on a program file (a *.sas file), and this used the default AUTOEXEC and the custom autoexec did not execute.

--
Paige Miller
MaryA_Marion
Lapis Lazuli | Level 10

Thank you for the reply. I finally figured out the problem. I had included a reset of ODS options in my code that included an ods _ALL_ close command. I needed to add an ODS listing command at the end and voilà everything runs just fine. Now I'm beginning to wonder what causes the listing command to change? It appears to happen when I simply run a new program outside of the autoexec. Interesting.

*ODS STATEMENTS RESET;
options mrecall;
%macro odsReset;
ods path reset;
ods _ALL_ close;
ods trace on;
ods noptitle;
ods graphics on;
ods listing;
%mend odsReset;
%odsReset;

 

Reeza
Super User
It looks like you may be using SAS Studio? If so, they have some code that runs at each submission as well. You can check the settings so that you can see the wrapper code - I think it's turned off by default but it's why your log numbers start at some weird number even in a new session.
Reeza
Super User
What do you mean by "always run"? Do you expect it to run each time you submit code? Or each time you start SAS?
MaryA_Marion
Lapis Lazuli | Level 10
I expected the autoexec to run each time I submit code. I leave it as a file in my home directory. I'm modifying it so often as I improve my skills that it just seems to be the best place to put it.
ballardw
Super User

Does the data set Timetrak exist in the Work library when this code "doesn't run"? If the set is there likely you have something very interesting going on and a Log entry from when it does not run will be needed.

 

Hint: you can simplify that to

data timetrak; 
   time1=time(); 
   date=date();                   
   file print;
   put "STAT 755 Clinical Trials" // 
    "Today's date is " date mmddyy8.  " and the time is" time1 hhmm6. // 
    "Author: Mary A. Marion" /; 
run; 

and if you don't actually need to use the data set Timetrak for anything else you can use Data _null_;

 

FWIW, I have had a somewhat similar data step in my Autoexec for more than 8 years and several versions of SAS that displays a countdown to a given date. I have never had it not run or fail to display the result.

MaryA_Marion
Lapis Lazuli | Level 10
Thank you for your reply. In lieu of doing a lot more extra work on this, I tried moving the TimeTrak code to its original location at the top of the autoexec. It's working fine again. Before I was ending up at the output data window. It appears I need some sort of closing code to take it back to the results window.

To get around this entire problem I created another macro called timetrak1 which I put at the top of working developing programs. It gives me a title line which I can change for different tasks.
 
This solves the problem well enough for me to proceed. Thanks for the help.
MM
 
MaryA_Marion
Lapis Lazuli | Level 10

I am not sure about the work directory. I will watch for that. I just tried an old version that ran and TimeTrak was in the work library so right now I think it best I just stay with what I have.

 

I have been wanting to save my graphs and am including the following code in my AUTOEXEC.  It appears before the TimeTrak code when TimeTrak is at the end of the AUTOEXEC. That is a little suspicious. It may be affecting the work library? Can you give me a better way to refer to the SAS work location? 

106 *ODS GRAPHICS;
107 %let
107 ! sasworklocation="/saswork/SAS_workB81000013419_odaws01-usw2.oda.sas.
107 ! com/SAS_workDB5300013419_odaws01-usw2.oda.sas.com";
108 ods listing gpath=&sasworklocation;
SYMBOLGEN: Macro variable SASWORKLOCATION resolves to
"/saswork/SAS_workB81000013419_odaws01-usw2.oda.sas.com/SAS_workDB5
300013419_odaws01-usw2.oda.sas.com"
109

Could that be causing some of the difficulty here? I had SAS studio give me the location which is how I got this long set of instructions. 

 

MaryA_Marion
Lapis Lazuli | Level 10
My autoexec included an ODS reset macro that included the command ods _ALL_
close. I needed to follow it with an ods listing command. It affected
output within the autoexec itself. Interestingly, when I ran code in new
programs the ods listing command seemed to take effect automatically and
output listings appear as normal.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 2717 views
  • 3 likes
  • 5 in conversation