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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 521 views
  • 2 likes
  • 3 in conversation