BookmarkSubscribeRSS Feed
wzimmerman
Fluorite | Level 6

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:

 

ID, CAL MONTH, DEMAND

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!

 

1 REPLY 1
TomKari
Onyx | Level 15

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 963 views
  • 0 likes
  • 2 in conversation