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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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