BookmarkSubscribeRSS Feed
georgel
Quartz | Level 8

Dear Users, 

 

Below I have a code for transpose the from long to wide the BHAR (1year=252 days, 2year=504 etc)

Is there is a way to do it at the same time for BHR having some kind of macro instead of repeating the procedure again for BHR 

 


data  test2; 
     set test1; 
     If  countdays=252 or countdays=504 or countdays=756;
run; 

*move the countdays as columns;
proc transpose data=test2(keep=cusip countdays BHARced)
				out=test3
				name=BHARced;
				id countdays;
				by cusip ;
run;

I have also attached the file.

Looking forward for  your prompt reply 

Many thanks in advance

George

 

3 REPLIES 3
georgel
Quartz | Level 8

Dear Kurt, 

 

I got a hint from here: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1n2i0ewaj1zian1ria5579z1zjh.htm

I put the proc transpose inside the loop.

 

Thank you very much for your prompt reply. 

ballardw
Super User

Bad things happen when you attempt to name variables starting with numerals and the SAS list code items don't work with them which makes that a poor choice to try to name things as 1Year 2Year etc.

 

This does basically what you want IF you don't try to start the variable name with a numeral.

proc format ;
value d2yr
252='Yr1'
504='Yr2'
756='Yr3'
;

proc transpose data=test2(keep=cusip countdays BHARced)
				out=test3
				name=BHARced;
				id countdays;
				by cusip ;
            format countdays d2yr.;
run;

But really, you should have a very specific reason for a data structure like that and printing or reporting it is not one.

 

 

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
  • 3 replies
  • 418 views
  • 1 like
  • 3 in conversation