New year refresher on reshaping data


ProblemSolversAs support analysts in the SAS Technical Support division, we answer many phone calls from SAS customers.  As members of the SAS Foundation team, we get questions that vary significantly in content from all of the areas that we support.  We offer coding tips and suggestions as well as point customers to SAS Notes and documentation. A common question that we are frequently asked is how to collapse a data set with many observations for the same BY variable value into a data set that has one observation per BY variable value.  Another way to phrase this question is: how do you reshape the data from “long to wide?”

Resources to Reshape Data

The following SAS Note illustrates how to use two TRANSPOSE procedure steps to collapse the observations for multiple BY variables:

Sample 44637: Double PROC TRANSPOSE method for reshaping your data set with multiple BY variables

If you prefer to use the DATA step rather than PROC TRANSPOSE, the following SAS Note provides a code sample that accomplishes the same purpose:

Sample 24579: Collapsing observations within a BY-Group into a single observation (when data set has 3 or more variables)

If the data set is “wide” and you’d like to expand each observation into multiple observations to make it a “long” data set, the following SAS Note is helpful:

Sample 24794: Expand single observations into multiple observations

Brief Overview of Some Resources

Since we’ve been discussing SAS Notes from the site, here is a brief overview of how to use the site to find other helpful items for your future coding projects.


  1. Go to
  2. On the left side of the page in the Knowledge Base section, select Documentation, Product Index A-Z, and then select your product of interest to access user guides and other documentation resources.

SAS Notes

  1. Go to
  2. On the left side of the page in the Knowledge Base section, select Samples & SAS Notes.
  3. From this page, you can type keywords in the Search box to get a list of relevant notes from both categories.
    Note: If you’re interested in specific types of notes (for example, samples or problem notes), select the type of note from the choices given on the left side of the page underneath Samples & SAS Notes.

It was a pleasure to work with you in 2015 when you contacted us for assistance. We look forward to another great year in 2016.


About Author

Kim Wilson

SAS Technical Support Analyst

Kim Wilson is a Technical Support Analyst in the Foundation SAS group in Technical Support. She has been a SAS user since 1996, and provides general support for the DATA step, macro, and Base procedures. She has written several papers and presented them at various SAS conferences and user events.

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Top