BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
somebody
Lapis Lazuli | Level 10

I have a dataset of fund holdings as attached. It is currently in a wide format. I would like to change it to a long format where there is one date column and one number_of_share column. Attached is 

I tried using the following code to transpose but it does not work. It says No variables to tranpose. I tried with a different dataset and it works

proc transpose data=sample2 out=sample_long;
	  by fund_ticker constituent_ticker name Detail_Holding_Type ;
	  run;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You have invalid SAS names in that CSV (numeric), which my University Edition dutifully changed to names with leading underlines on import.

Then this code worked:

proc sort data=import;
by fund_ticker constituent_ticker name Detail_Holding_Type;
run;

proc transpose data=import out=sample_long;
by fund_ticker constituent_ticker name Detail_Holding_Type;
var _:;
run;

Note that there are a lot of ambiguous observations in the imported dataset (multiples for the same keys), which leads to more output columns than expected.

View solution in original post

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

please try the below code

 

proc transpose data=have;
by fund_ticker constituent_ticker name detail_holdeing_type;
var 20180102 20180103 20180104 20180105 20180108;
run;
Thanks,
Jag
Kurt_Bremser
Super User

You have invalid SAS names in that CSV (numeric), which my University Edition dutifully changed to names with leading underlines on import.

Then this code worked:

proc sort data=import;
by fund_ticker constituent_ticker name Detail_Holding_Type;
run;

proc transpose data=import out=sample_long;
by fund_ticker constituent_ticker name Detail_Holding_Type;
var _:;
run;

Note that there are a lot of ambiguous observations in the imported dataset (multiples for the same keys), which leads to more output columns than expected.

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

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