BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
rkd84
Calcite | Level 5

Dear Friends, 

 

I am trying to transform the existing data (Presently in this format):

 

Name201320142015201620172018201920202021
3M India Ltd.11.1210.9510.710.6210.3810.2510.211.0310.66
A B B India Ltd.7.937.937.87.997.87.997.968.327.97
A C C Ltd.2.562.612.562.522.512.472.592.712.57
A I A Engineering Ltd.5.335.054.824.824.674.754.684.714.85
A P L Apollo Tubes Ltd.8.758.528.558.538.358.238.468.458.48

 

 

To Something like This:

NameYearMTBV
3M India Ltd.201311.12
3M India Ltd.201410.95
3M India Ltd.201510.7
3M India Ltd.201610.62
3M India Ltd.201710.38
3M India Ltd.201810.25
3M India Ltd.201910.2
3M India Ltd.202011.03
3M India Ltd.202110.66
A B B India Ltd.20137.93
A B B India Ltd.20147.93
A B B India Ltd.20157.8
A B B India Ltd.20167.99
A B B India Ltd.20177.8
A B B India Ltd.20187.99
A B B India Ltd.20197.96
A B B India Ltd.20208.32
A B B India Ltd.20217.97



I am working on more than 500 stock data as of now. Can someone please suggest an easy and efficient way to do this?

Attaching a sample file for reference.

Thanks in Advance
Ritesh



1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

Maybe like this:

options validvarname=v7;

proc import datafile="FakeData\TransposeNumNames.xlsx" dbms=xlsx replace out=have;
   sheet= "have";
run;

proc transpose data=have out=transposed(drop=_name_ rename=(col1=mtbv)) label=year;
   by Name;
   var _:;
run;

I won't open any excel files, so i build one using the table you have posted.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

You seem to have an Excel issue, you should ask this question in an Excel-centered support forum.

(Numbers are not valid variable names in SAS)

If you want to do this in SAS, provide a SAS dataset in usable form (data step with datalines).

In SAS, use PROC TRANSPOSE to transpose from wide to long, and a follow-up DATA step to convert _NAME_ to year.

 

andreas_lds
Jade | Level 19

Maybe like this:

options validvarname=v7;

proc import datafile="FakeData\TransposeNumNames.xlsx" dbms=xlsx replace out=have;
   sheet= "have";
run;

proc transpose data=have out=transposed(drop=_name_ rename=(col1=mtbv)) label=year;
   by Name;
   var _:;
run;

I won't open any excel files, so i build one using the table you have posted.

rkd84
Calcite | Level 5

proc transpose data=WD.BVTMV out=T_BVTMV(drop=_name_ rename=(col1=mtbv)) label=year;
by Company_Name;
var _all_;
run;

It worked. 

Thanks a ton. 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 740 views
  • 2 likes
  • 3 in conversation