BookmarkSubscribeRSS Feed
BC01
Calcite | Level 5

I have some simplified dummy data and desired results below. The columns are ID, Company, FiscalYear, Revenue, Net Income, and Expenses. I want to transpose the values of Revenue, Net Income, and Expenses into one column called Values, with another column called Item that indicates which financial item it is. I want to keep the other columns. Below is the desired result. The exact order/sorting is not required. Notice that sometimes there is NULL data (eg. C 2020), or yearly data is absent (eg. B 2020).

 

How can I implement this?

 

Original Data Set

IDCompanyFiscalYearRevenueNet IncomeExpenses
1A2019     982.589        886.813     95.776
2B2019     807.335        727.985     79.350
3C2019  1,128.979     1,024.482  104.497
1A2020  1,005.182        909.667     95.515
3C2020 .  .  . 
1A2021     612.943        555.705     57.238
2B2021     898.566        812.447     86.119
3C2021     640.070        577.160     62.910

 

Desired Result

IDCompanyFiscalYearItemValue
1A2019Revenue          982.589
1A2019Net Income          886.813
1A2019Expenses            95.776
2B2019Revenue          807.335
2B2019Net Income          727.985
2B2019Expenses            79.350
3C2019Revenue       1,128.979
3C2019Net Income       1,024.482
3C2019Expenses          104.497
1A2020Revenue       1,005.182
1A2020Net Income          909.667
1A2020Expenses            95.515
3C2020Revenue . 
3C2020Net Income . 
3C2020Expenses . 
1A2021Revenue          612.943
1A2021Net Income          555.705
1A2021Expenses            57.238
2B2021Revenue          898.566
2B2021Net Income          812.447
2B2021Expenses            86.119
3C2021Revenue          640.070
3C2021Net Income          577.160
3C2021Expenses            62.910
1 REPLY 1
Tom
Super User Tom
Super User

That is what PROC TRANSPOSE is for.

Looks like your key variables ID, COMPANY and FISCALYEAR uniquely identify the observations in your original dataset.

So use those in the BY statement.  If the data is not sorted by those variables yet you can add the NOTSORTED keyword to the BY statement.

List the other three variables in the VAR statement.

You can use the NAME= option to control the name given for the variable that has the name of the original variable.

You can use the RENAME= dataset option to rename the output variable.

proc tranpose data=HAVE name=ITEM out=WANT(rename=(col1=VALUE)) ;
  by ID Company FiscalYear NOTSORTED ;
  var Revenue NetIncome Expenses ;
run;

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
  • 872 views
  • 1 like
  • 2 in conversation