BookmarkSubscribeRSS Feed
Lilly2012
Calcite | Level 5

Hi SAS users,

I have uploaded data from Bloomberg and the data is sorted in a columns as follow

Company1Company2Company2022
Data1-1X1-1 (these are numbers for Tobin's Q)Date2-1X2-1 (these are numbers for Tobin's Q)Date2022-1X2022-1
Date1-2Y1-2Date2-2Y2-2Date2022-2Y2022-2
Date1-3Z1-3Date2-3Z2-3Date2022-3Y2022-3

I would like to sort the data this way

CompanyNameTobin'sQDate
Company1X1-1Date1-1
Company1Y1-2Date1-2
Company1Z1-3Date1-3
Company2X2-1Date2-1
------------
Compnay2022Y2022-3Date2022-3

I have tried Proc Transpose but it will not produce the desired results. Would arrays help? if so how. Any ideas are welcome.

Thank you

1 REPLY 1
jakarman
Barite | Level 11

The transpose is the first idea. Perhaps more easy to do some datasetcoding.

The thoughts:

- Define two array-s for all the company 1/ date vars 2/ tobinsq. Pehaps the naming is helping.

  SAS(R) 9.4 Statements: Reference (array)

- the in a do loop for all variables write to a SAS new dataset:   company-id , date(i),tobinq(i)

- let te datastep proceed for all  records.

The result will be a dataset with the columns you need, just the order is different.

Ordering the data can be done by creating indexes. Base SAS(R) 9.4 Procedures Guide

Or by sorting. Proc sort (company/date)
As the dataset is that small it could easily be fit in memory or being buffered. Unless there are many timemoments (10 minute snap-shots for over many years.)  

---->-- ja karman --<-----

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!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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