I am using SAS 9.2 at the moment and I understand that under Tools > Options > Preference > Results > Create HTML shows the directory of where my html page is going to be saved whenever i generate a html.
Is there any script that I can write that will automatically direct my html page to be saved to my desired directory without having to manually go to Tools > Options to change it every time I run the script ?
I'm not sure what you mean by a "script". However, with SAS program code, you can absolutely direct your HTML output to a specific directory location.
ods html file='c:\temp\myfile1.html';
...sas code to generate output ....
ods html close;
ods html path='c:\temp' (url=none)
....sas code and sas/graph code to generate output...
ods html close;
The first method is what you would use to create simple tabular output (no graphs) and your output would go to the fully qualified path name that is shown in the FILE= option.
The second method is the recommended method to use when you are going to create graphic output ... by using PATH= and GPATH=, you guarantee that any tabular and graphic output will be written to the desired location (in this case, the same location, c:\temp) and the URL=NONE option informs ODS HTML to build a relative anchor tag for any HREF information that it might use (such as in an <IMG> tag).
I find that, for me, this is the preferred method for controlling the location of all ODS output, rather than the Tools-->Options method because it gives me the most control over my program output.
I am guessing that the issue was that "C:\temp" was not in existence at the time the program was run. ODS HTML will not create a directory. The directory that you write to using either file= or path= must already be created and you must have operating system level write access to the directory.
So, for example, if you have:
ODS HTML file='c:\reports\fred\myfile.html';
And c:\reports\fred directory does not exist, you will get an error message. Or, if the directory exists, but you do not have write access to c:\reports\fred directory, you will also get an error message.
the windows platform may not have a c:\temp folder, but does use an environment variable TEMP pointing to a corresponding location usually within the users profile.
SAS refers to windows environment variables through the %sysget() function, or with an ! prefix, like may be seen in SAS configuration files, with lines like
-WORK "!TEMP\SAS Temporary Files"
In our SAS code we can use similar syntax to write to TEMP using code like
ODS html file='!temp\myfile1.html';