Help using Base SAS procedures

Using Loop to create data columns

Reply
Super Contributor
Posts: 400

Using Loop to create data columns

I need to create a data set from scratch.

I need to create some year columns that goes from 1999-2003 then skips a year till 2007.


My data set should look like this
y1999 y2000 y 2001 y2002 y2003 y2005 y2007

Is this possible?

I'm not sure if this is the correct path to take but I have a table that has a variable that has all the years for a product. Some products have some of the years and some have all. I'm trying to find the best way to display that data in a matrix.

Thank you for your help
Super Contributor
Super Contributor
Posts: 3,174

Re: Using Loop to create data columns

Look at PROC TRANSPOSE to convert a "vertical" observation oriented SAS file to a "horizontal" column oriented SAS file.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

proc transpose site:sas.com
Valued Guide
Posts: 2,175

Re: Using Loop to create data columns

creating the columns needs no loop, just a simple statement like:[pre] length y1999 -y2003 y2005 y2007 ;[/pre]defines the columns but does not dynamically construct or fill the columns based on the data. For that, use Scott's method - proc transpose

good luck
peterC
Super Contributor
Posts: 400

Re: Using Loop to create data columns

Thank you both so much for all your help.

The length statement did what I wanted. Thanks

The proc tranpose actually corrected a different issue I was having.


Thanks again for the quick and awesome help.
Ask a Question
Discussion stats
  • 3 replies
  • 109 views
  • 0 likes
  • 3 in conversation