BookmarkSubscribeRSS Feed
nicolelai
Calcite | Level 5

Hello there,

I am trying to reshape my data from wide to long format. However, I face some difficulties (that I suspect it is due to the variable names/companies ). If I need to rename the variables (900 companies), I wonder what is the best way to solve this and get my data reshaped.

The data format that I am having is shown as follow:

Date          SAPU_MK_EQUITY     NYL_MK_EQUITY   KEYA_MK_EQUITY

1/2/2000     0.013                          N/A                         0.024

1/3/2000     0.013                          N/A                         0.024   

1/4/2000     0.013                          N/A                         0.024

I would like to reshape the data to this format:

Date          Company                           EPS

1/2/2000     SAPU_MK_EQUITY          0.013

1/2/2000     NYL_MK_EQUITY             N/A

1/2/2000     KEYA_MK_EQUITY          0.024

1/3/2000     SAPU_MK_EQUITY          0.013

1/3/2000     NYL_MK_EQUITY             N/A  

1/3/2000     KEYA_MK_EQUITY          0.024

1/4/2000     SAPU_MK_EQUITY          0.013

1/4/2000     NYL_MK_EQUITY             N/A  

1/4/2000     KEYA_MK_EQUITY          0.024

Thank you.

Sincerely,

Nicole

1 REPLY 1
Haikuo
Onyx | Level 15

proc transpose can do the trick:

proc transpose data=eps2 out=want(rename=(_name_=company col1=eps));

by date;

var SAPU_MK_EQUITY--NAT_MK_EQUITY;

run;

Haikuo

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 Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 320 views
  • 0 likes
  • 2 in conversation