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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 610 views
  • 0 likes
  • 3 in conversation