Aliasing Program Symbols


A longstanding debate among CSPro programmers concerns the naming convention to use when adding items to a dictionary. For example, you might have five questions: name, relationship, sex, age, and marital status. One approach is to match the item name to the question topic, like:

  • NAME
  • RELATIONSHIP
  • SEX
  • AGE
  • MARITAL_STATUS

This can lead to very long names though. For example, you might ask: children ever born [males alive], children ever born [females alive], children ever born [males dead], children ever born [females dead], and so on. Having a name like CHILDREN_EVER_BORN_MALE_ALIVE is very descriptive, but typing it in logic is very cumbersome.

Another approach is to use the question number for the name, so the above might be something like:

  • P01
  • P02
  • P03
  • P04
  • P05

These short names are very easy to type in logic so they are useful in batch programming, but they are cryptic to people who are looking at your code for the first time.

A third approach is a hybrid, combining the question number and the variable name:

  • P01_NAME
  • P02_RELATIONSHIP
  • P03_SEX
  • P04_AGE
  • P05_MARITAL_STATUS

The advantage of this approach is that, unlike the first approach, it is easy to identify what section in the questionnaire each item comes from (P = population), but the downside is the names are the longest of all approaches.

I personally program using the second approach. I find that when you are working on a survey or census for weeks or months on end, after just a short time you will know the questionnaire contents in and out, and you will know what P03 is versus P23 versus H15. When I am writing batch edits, I like that I can write short names for the variables. However, if distributing a dictionary with the data set, I might create a duplicate CSPro dictionary with longer and more descriptive item names.

CSPro 5 has a feature, aliases, that simplifies this dilemma. If you want to use both long and short names, you can alias a shorter name to a longer name. An alias is another way to refer to the item in logic. This means that you can create your dictionary using long descriptive names and then use short names in logic. For example:

alias   P01 : P01_NAME,
        P02 : P02_RELATIONSHIP,
        P03 : P03_SEX,
        P04 : P04_AGE,
        P05 : P05_MARITAL_STATUS;

This code would be placed at the top of your logic in the PROC GLOBAL section. After the alias statement, P04 and P04_AGE are interchangeable in the code. Any "symbol" in logic can be aliased, including item and record names, form and group names, and working storage variables. Only one alias can exist for each symbol though.