You are here: Fearntech »

Category : Programming

Inline styles in ODS PRINTER output

Controlling formatting of ODS PRINTER (PDF/RTF) outputs has always seemed like a bit of a black art to me, but there are usually ways of getting around potential issues if you know where to look. With SAS V9.2, there are some new and probably unknown features, including the use of ‘inline styles’.

For a good introduction to this I recommend having a look at this SAS document “How to Add a Little Spice to Your PDF Output“.

As a quick example, you need to specify an escape character eg. “^” or “¬”.
ods escapechar="^" ;
Then, you can use that escape character “^” in a number of elements such as a title or PROC REPORT ‘LINE’ statement:
title1 "Colour ^{style [color=red] red} and ^{style [color=blue] blue}";
There are a couple of useful new functions NBSPACE and NEWLINE.
Example:
title1 "First line^{newline 2}and this line after 2 blank lines";

Other useful ODS PRINTER/ODS PDF documents:

Windows Boot CD

If your Windows XP or Windows Vista computer becomes totally ‘messed up’ then it is sometimes necessary to find an alternative way to log in to your computer to right the problem or in some cases to actually delete Windows and start from fresh.

Recently my laptop has been freezing and despite numerous updates and tests I was unable to trace the problem. As I always have all my data backed up in three places, I decided to create a fresh install of Windows Vista (this often cures problems and reduces the risk of having long running virus infestations). Unfortunately the new install still had the freezing/crash issue and it did this whilst in the middle of a Windows Update download which totally prevented Windows from starting at all. Windows would not even start in ’safe’ mode or in ‘last good configuration’ mode.

I tried to run a new Windows install but again this failed, probably because the Master Boot Record (MBR) was corrupted.

No problem I thought, just download a ‘boot disc’ from the internet using my desktop machine.

This proved to be a tedious and frustrating task, with solutions such as BCD and BFD not working for me out of the box, and proving a bit too technical even for myself.

So, to save other people the same frustrations I will jump straight to the solution (note: if you only have one computer then make sure you do this BEFORE your computer goes wrong!).

  1. Download Hiren’s BootCD from here: http://www.hirensbootcd.net/ (This is not the official Hiren’s site but I couldn’t actually find a download link on the official site!).
  2. Extract the files in the ZIP file to a suitable folder (doesn’t matter where).
  3. Put a blank writeable CD into your CD burner.
  4. Start up some ISO burning software. I downloaded this free program: http://www.ntfs.com/iso-burning.htm
  5. Burn from your ’suitable folder’ to CD.
  6. On your ‘messed up’ computer, switch on, go into the BIOS setup screen (F2 on my laptop).
  7. Make sure that CD/DVD drive is enabled and first in the list of Bootable devices.
  8. Re-boot, select Boot from CD.
  9. You will then have a choice of ‘Mini XP’ or command prompt, both of which will allow you to view your devices/drives.
  10. My solution was then to format the C: using the Disk Management utility, and then reinstall Windows ‘as normal’.

WARNING: If you are unsure about ‘playing around’ with computers then seek advice at an early stage – you could lose all your data….  Always make sure you backup your important data BEFORE something goes wrong, and always keep at least two copies. It is worth investing in online backup facilities as an extra precaution.

Querying SAS option status in Base SAS

Some SCL functions are available to Base SAS but you cannot use the SCL functions OPTGETN and OPTGETC to find out what the current status of certain SAS Options are.

In this case you can use the OPTSAVE and OPTLOAD Base SAS procedures.

For example, if you wanted to query the current MPRINT and NOTES option settings so that you could change the options temporarily and then return them to the original values then you could use the following Base SAS code:

* Retain the current MPRINT and NOTES options in a dataset *;
proc optsave out=_sysoptions (where=(optname in ('MPRINT' 'NOTES')));
run;

* Force the options to not display generated macro code/notes *;
options nomprint nonotes;

.. other SAS macro code here ...

* Reset the options back to their original values *;
proc optload data=_sysoptions;
run;

You might want to do this where an external SAS macro called a sub-macro and the external macro may have the MPRINT/NOMPRINT and NOTE/NONOTES options set. You could then force the options to not display macro code and program notes while the sub-macro is running, but return the settings to their original values after sub-macro execution is complete.

Using PROTECTSPECIALCHARS in SAS ODS to allow HTML tags

How to use PROTECTSPECIALCHARS to allow HTML tags in your data when using HTML ODS in SAS.

When sending output to the HTML destination using PROC REPORT a number of the usual attributes are not available. For example the FLOW attribute on the DEFINE statement. It can therefore be necessary to include HTML tags within the data to be interpreted when the HTML page is viewed in a browser.

The problem is that if for example you enter ‘<BR />’ into your data then SAS will protect the characters and your output will actually be converted into character entities eg. ‘&lt;BR /&gt;’. The solution is to use the protectspecialchars attribute within style definitions, which when set to OFF causes SAS to ignore special characters and output exactly as entered.

An example PROC REPORT statement is shown below, note how the protectspecialchars is only being applied to the data in this case and so any special characters in column headers will still be protected.

proc report data=mydata nowindows
style (header) = [font_face=helvetica font_size=2]
style (column) = [font_face=helvetica font_size=1
protectspecialchars=off];

Adding parameters to the OnAction property of Excel buttons

Sometimes you need to pass parameters via a button in Excel but the standard OnAction property syntax does not allow this. If you try .OnAction=”myProc(99,’Some text’)” you will receive an error. But there is a way to get around this.

You can add a parameter to the OnAction property of the button. If you had a procedure like this:

Sub myProc(id As Integer, myText As String)
MsgBox (id & " " & myText)
End Sub

You can set the OnAction property of a button as follows:

sheet1.Shapes(1).OnAction = "'myProc 99,""Some text""'"

Careful with the quotes and double quotes, you need single quotes around the entire procedure call and parameters, you need repeated double quotes around strings. Separate parameters with commas.

Using ANNOTATE to add text to a plot in SAS/GRAPH

Using ANNOTATE to add text to a plot in SAS/GRAPH

An example which creates an annotate dataset with a text label to be displayed in a plot, using GPLOT in SAS/GRAPH

* Adds text TEXT HERE at data point 23 on x-axis, 100% *;
* position on y-axis *;

data annot;
length function $8;
x=23;
function='LABEL'; text='TEXT HERE'; color='LIGR';
position='2'; xsys='2'; ysys='1'; y=100; size=1.5;
output;
run;

proc gplot....
plot ... / annotate=annot;
run;
quit;