Desktop productivity for business analysts and programmers

Structuring Data in SAS EG

New Contributor
Posts: 4

Structuring Data in SAS EG

I have a SQL database that I have connected to. It has over 8 million rows of customer data. The data runs from 2004-2015.


I have broken the data up into years and then sorted them by month.


I then used our utility's unique identifier in a query to only provide the unique numbers.


What I want to do is use the unique ID as the first column and a column for Jan 2004 and if will take all of the data for each customer and place it in that column if the date is Jan 2004 and so on for each year.


Here is what the data currently looks like:



a         1                     6

b        12                    6

f          1                     4

d         2                     3

e         6                     2

f          2                     7


So the customers have 12 months worth of data and I need the demand data for each month as a new column.


Here is what I would like it to look like:


ID,   JAN 2004, FEB 2004

a          6               6

b          6               7

c          6               8

d          7             10

e          9             12

f           6               6


Any help is greatly appreciated!


Posts: 1,334

Re: Structuring Data in SAS EG

Posted in reply to wzimmerman

First, if you have more than one record per customer / month, use the Summary Statistics task and summarize by customer and month, to get a total. Don't print the output, get an output dataset instead.


Once you have this, or starting with this if it's what you've got, you should have a dataset that looks like:


ID Month Demand
a 01Jan2004 2525
a 01Feb2004 5566
  . . .  
a 01Dec2004 7345
b 01Jan2004 9866
  . . .  
b 01Dec2004 5324



Then you can use the Data | Transpose... task to create your output. Select ID as a Group variable, Demand as the Transpose variable, and Month as the "New Column Name" variable.

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation