Hello,
I am a novice SAS programmer assisting research project, and I need help with data manipulation.
My data is as follows:
| KIS | Stock | Name | Sum2000 | Sum2001 | Sum2002 | Sum2003 | Sum2004 | Sum2005 | Sum2006 | Sum2007 | Sum2008 | Sum2009 |
| 000292 | 059210 | AA | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 000442 | 039020 | BB | 0 | 0 | 0 | 944079000 | 734022000 | 1093304000 | 320309000 | 1674600000 | 0 | 1699003000 |
| 000671 | 036480 | CC | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 001097 | 039230 | DD | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
I want to manipulate the data to look like as follows:
| KIS | Stock | Name | Sum |
| 000292 | 059210 | AA | 0 |
| 000292 | 059210 | AA | 0 |
| 000292 | 059210 | AA | 0 |
| 000292 | 059210 | AA | 0 |
| 000292 | 059210 | AA | 0 |
| 000292 | 059210 | AA | 0 |
| 000292 | 059210 | AA | 0 |
| 000292 | 059210 | AA | 0 |
| 000292 | 059210 | AA | 0 |
| 000292 | 059210 | AA | 0 |
| 000442 | 039020 | BB | 0 |
| 000442 | 039020 | BB | 0 |
| 000442 | 039020 | BB | 0 |
| 000442 | 039020 | BB | 944079000 |
| 000442 | 039020 | BB | 734022000 |
| 000442 | 039020 | BB | 1093304000 |
| 000442 | 039020 | BB | 320309000 |
| 000442 | 039020 | BB | 1674600000 |
| 000442 | 039020 | BB | 0 |
| 000442 | 039020 | BB | 1699003000 |
| 000671 | 036480 | CC | 0 |
| 000671 | 036480 | CC | 0 |
| 000671 | 036480 | CC | 0 |
| 000671 | 036480 | CC | 0 |
| 000671 | 036480 | CC | 0 |
| 000671 | 036480 | CC | 0 |
| 000671 | 036480 | CC | 0 |
| 000671 | 036480 | CC | 0 |
| 000671 | 036480 | CC | 0 |
| 000671 | 036480 | CC | 0 |
In short words, after AA's Sum for Years 2000-2009 ends, then BB's Sum for Years 2000-2009 follows, and CC's Sum for Years 2000-2009 follows, and so on.
Could anyone provide SAS code for doing this?
It seems like I have to use proc transpose to do this, but I don't know how to duplicate rows along with proc transpose.
Since there are thousands of firms, I really need help with coding.
I'd highly appreciate anyone's help!
Please explain how this is any different than the question you asked in https://communities.sas.com/t5/SAS-Programming/Transposing-column-data-to-create-duplicate-rows/m-p/...
And why the proposed solutions weren't helpful. The first proposed solution would require exactly one character change to get this output.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.