Coalesce in SAS

Coalescing refers to the process of checking the value of each input parameter in the order in which they are listed and returns the first non-missing value. In SAS, the behavior of each of the coalesce functions depends on the processing context, either in a data step or in a PROC SQL statement. These differences are important to acknowledge, especially when the code is migrated from PROC SQL to a data step.

Suppose, for example, that the following piece of code needs to be modified into a data step:

proc sql;
  create table foo2 as
  select coalesce(colum1, column2) as coalesce_column
  from foo;
quit;

The intuitive approach would be to simply rewrite the code as follows:

data foo2;
  set foo;
  coalesce_column = coalesce(colum1, column2);
run;

Although this approach seems to be correct at first glance, it may cause a potential issue: the coalesce function in the context of a data step treats parameters as numeric values. More specifically, if column1 and column2 are characters, the automatic SAS conversion kicks in by trying to convert these values to numerics. If such a conversion fails, a null value will be passed to the function. Simply switching to the character-compatible function, coalescec, may still have some side-effects as we will demonstrate in the following sections.

Slide Number in PowerPoint

Recently, I was working on a PowerPoint presentation based on a specific template from a client. As I was about to print the deck, I realized that the slide numbers were missing. As I struggled to figure out how to make the slide number to appear on all the slides, I thought it would be good to share here my experiences. The illustrative screenshots have been taken from PowerPoint 2003. The approach should be similar for more recent versions of PowerPoint.

Formatting scaled numbers

Standard formatting in .NET is sometimes not enough to fill specific requirements. For example, when high-level financial reports from big corporations need to be produced, the numbers dealt-with are generally around hundred of millions. Consider the following report where the scale and the currency (M$) is being displayed in the row header.

Quarter 1Quarter 2
New York (in M$)102.7621.40
Florida (in M$)32.7667.40

In order to achieve this formatting, a straightforward solution would be to apply a scaling factor to the numbers beforehand.

string.Format("{0:N2}", valueToFormat / 1000000); 

Sometimes, it is not appropriate nor possible to scale the numbers. In this situation, number scaling using the "," custom specifier could be used. Note the use of two commas since the number to be formatted is divided by 1000 for each comma:

decimal valueToFormat = 1345278000.346M;
string.Format("0:#,#,,", valueToFormat ); // displays 1,345 with the invariant culture

MWSnap Review

MWSnap Icon When it comes to create screenshots, I often use MWSnap, a freeware written by Mirek Wojtowicz. This tool offers all the core functionalities one may expect from a screenshot application. MWSnap was recommended to me by Michael Olivero.

MWSnap

Order returned by GetMethods

When calling the GetMethods function which lists the methods for a given type, we should keep in mind that this function does not return methods in a particular order. More specifically, the methods are not necessarily in the same order it has been declared in the source code. This discrepancy is due to some caching performed by the .NET Framework for better performance as explained in a post by Haibo Luo. This article is aimed at outlining solutions to order the methods returned by GetMethods in the declaring order.

Pages