As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Solutions in the Round -- Ways to Control the Order of Classification Levels when the Desired Order is Neither Internal nor Formatted

From sasCommunity
Jump to: navigation, search

Introduction

From the WUSS abstract for this topic

Join us as we discuss several ways to control the order of classification levels when the desired order is neither internal nor formatted. We will identify several methods for doing this and will discuss the merits of each way. Solutions in the Round is an exciting new section [at WUSS 2014]. The format is simple: we sit in a circle and discuss the many ways to approach and address a programming problem, and we'll identify situations where one approach might be more useful than another. We will keep notes, and those notes will be posted on sasCommunity.org where we can continue the discussion and allow other to join in after the conference. We hope to engage users from all different perspectives and experience levels to participate in these discussions.

Discussion at WUSS

To facilitate the discussion, we used an example. The SASHELP.HEART dataset contains a variable called SMOKING_STATUS, which has values of 'Light', 'Moderate', and 'Heavy'.

We can create a format for this variable:

PROC FORMAT;
   value $smoking (NOTSORTED)
   'Light' = 'Light'
   'Moderate' = 'Moderate'
   'Heavy' = 'Heavy';
RUN;

The default in SAS is to store formats in alphabetical order. When we specify the NOTSORTED option, the format is stored in the order that is was created here. We control the order of the format by how we sequence the code, above. Then, we can use a procedure such as PROC TABULATE with ORDER=DATA specified:

PROC TABULATE data=sashelp.heart;
   format smoking_status $smoking.;
   class smoking_status/preloadfmt order=data;
RUN;
  • suggestion: use an index

More notes:

  • default: uses formatted in alpha order
  • alternative: to use internal, "turn off" format e.g. FORMAT x4.;
  • To change order create new variable with values in desired order
  • create 2 formats
  • ORDER=INTERNAL option
  • add numeric prefix to format:
    • 1. light
    • 2. moderate
    • 3. heavy
  • can use ORDER=DATA (but beware)

Further Discussion -- Open to All

Please join the conversation! Also, if you were one of the live participants, please feel free to correct any mistakes or omissions from our original discussion.

  • Can anyone help elaborate on why we should beware of ORDER=DATA? Also, it would be nice to provide some links to papers on this topic. --Otterm1 (talk) 13:26, 2 January 2015 (CST)