February 2012 Quick Tips

Tip #1: Creating new styles with SAS Enterprie Guide Style Manager

Tip #2:  The best debugging statement: PUTLOG

Tip #1

Creating New Styles with SAS Enterprise Guide Style Manager

Once a report has the correct data presented in a meaningful way, the next most important step is getting the right look for your report.  You can create a custom style in SAS Enterprise Guide with your company colors, fonts, logos, etc.  You can save and reuse this style later for any or all of your reports.  Please note that the steps below are written for SAS Enterprise Guide 4.3, and there may be variability with earlier versions of the software.

To open the Style Manager, go to Enterprise Guide’s Tools menu and select Style Manager.  Then to create a new style, click the Add button.  Select Add new based on existing style.  Type a name in the Style Name box.  From the Based On drop-down menu, select an existing style that is close to what you want.  Click OK.


On the Style List, highlight the new style name.  Click Edit to open the Style Editor.  To change text and background properties, in the Style Editor, select the Text tab.  In the Preview Area, click the section you would like to change.  Use the drop-down menus to select the text size, style, color, and alignment and the background color.  To modify the report borders, click on the Borders tab.


To add an image, select the Images tab.  Check Use background image or Use a banner image.  Click Select.  Navigate to the image.  Click Open.  Click OK to close the Style Editor.

To make the new style the default for reports, highlight the style on the Style List.  Click Set as Default.  Click OK.  To apply the new style to an existing report, in the Process Flow or Project Tree, right-click the report.  Click Properties.  From the Style drop-down menu, select your new style.  Click OK.  Click the report.

Now you can easily standardize the look of your reports across your processes and company.  You can also import an existing style sheet that your company has.  Either way, not only will your report contain the important information that decision makers need, but you will also be able to easily distribute it with a consistent, attractive look.

Tip #2

An Easy Data Step Debugging Statement


In many ways, simple statements are the best in SAS.  One frequent problem that occurs is a data step is not doing something correctly like selecting rows, etc.  One easy way to let SAS help us debug it is to display constant and variable information at critical spots as our program runs.  While PUT can also be used, PUT can direct to other destinations, whereas PUTLOG always writes to the SAS log and as such, makes it simple for debugging.   


For example, in the following program, why wasn’t Bloomington selected?                        


data mycity;

  infile datalines;

  Input @1 state  $2. @10 County $10.

        @20 City $10. @35 Rate;

  If State ='MN';

  If County='Hennepin';

  If City  = 'Bloomington';


MN        Hennepin  Bloomington    100

WI        Dane      Monona         200

NOTE: The data set WORK.MYCITY has 0 observations and 4 variables.


The problem must be: 

1.       Bloomington doesn’t exist in our file.

2.       We input in incorrectly.

3.       One of the three subsetting IF statements discards it.

By displaying some or all of the variables along with an “eye catcher” around the possible offending statements we can see the results.


42 data mycity;

43   infile datalines;

44   Input @1 state $2.  @10 County $10.

45         @20 City $10. @35 Rate;

46   putlog '*** Before State Check' _all_;

47   if State ='MN';

48   putlog '*** Before County Check' state= county= city=;

49   if County='Hennepin';

50   putlog '*** Before City Check' state= county= city=;

51   if City  = 'Bloomington';

52   putlog '*** After City Check' state= county= city=;

53   datalines;

*** Before State Checkstate=MN County=Hennepin City=Bloomingt Rate=100 _ERROR_=0 _N_=1

*** Before County Checkstate=MN County=Hennepin City=Bloomingt

*** Before City Checkstate=MN County=Hennepin City=Bloomingt

*** Before State Checkstate=WI County=Dane City=Monona Rate=200 _ERROR_=0 _N_=2

*** Before State Checkstate=IL County=Cook City=Chicago Rate=300 _ERROR_=0 _N_=3


It looks like in this case, the input statement never read the city correctly.


PUTLOG can produce a lot of output, so stopping after a few records or a more exclusive IF statement can be used to limit printing.