LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2009, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 4 Oct 2009 18:36:11 -0500
Reply-To:     "Data _null_;" <iebupdte@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Data _null_;" <iebupdte@GMAIL.COM>
Subject:      Re: Dynamic column ordering
Comments: To: dave crimkey <>
In-Reply-To:  <>
Content-Type: text/plain; charset=ISO-8859-1

PROC TRANSPOSE creates variable names from ID variables in the order they are encountered. If you want a specific order you can 1) reorder the variables "by name" after they are created by transpose. or 2) you can create the proper order in the first few observations processed by PROC TRANSPOSE such that the proper order is achieved.

Method 2 has the advantage of creating variables for ID values that might not be in the data, as in this contrived example.

proc plan seed=437500408; factors id = 10 ordered year = 1 of 3 month = 4 of 12 y = 1 of 100 ; output out=sime year nvals=(2007 2008 2009); run; data sime; set sime; date = mdy(month,1,year); format date yymmn.; run; proc print; run; ** The default PROC TRANSPOSE; proc transpose data=sime out=wide1; by id; var y; id date; idlabel date; run; proc contents order=varnum; run;

** Create special ID=. with values of DATE to establish the proper variable order.; proc summary data=sime; output out=dateinfo(drop=_:) min(date)=min max(date)=max; run; data sime2 / view=sime2; if 0 then set sime; set dateinfo; do date = min to max; output; date = intnx('month',date,0,'end'); end; do until(eof); set sime end=eof; output; end; stop; run; proc transpose data=sime2 out=wide2(where=(not missing(id))); by id; var y; id date; idlabel date; run; proc contents order=varnum; run; proc print; run;

On 10/4/09, dave crimkey <> wrote: > I seem to have two problems. One is that even though Transpose creates columns 2007 200701 etc., nothing else seems to recognize those column names.. Here's my transpose -- the values 2007, 200701 etc., are contained in variable secondvar. I want them ordered in month order so 2007, 200701 - 200712, 2008, 200801-200812, 2009, 200901-200912. > > proc transpose data=sime out=all ; > byfirstvar thirdvar fourthvar fifthvar; > idsecondvar; > run; > procsortdata=all (drop = _LABEL_); > byfirstvar thirdvar fourthvar fifthvar; > run; > > I've heard that I can use dictionary.columns to dynamically order the columns the way I want but am not sure how to use that. > > Thanks > > > > > ----- Original Message ---- > From: Arthur Tabachneck <art297@NETSCAPE.NET> > To: SAS-L@LISTSERV.UGA.EDU > Sent: Sunday, October 4, 2009 2:52:06 PM > Subject: Re: Dynamic column ordering > > Dave, > > Please provide the list with some sample data, as well as your proc transpose > and how you actually want the columns ordered. > > Art > ----- > On Sun, 4 Oct 2009 11:15:23 -0700, dave crimkey <d_crimkey@YAHOO.COM> wrote: > > >I've created a report that results from a transpose of year/month. Since the > columns look like the following: 200701 200702.....200909 they are not coming > out in the correct order. I don't want to hard-code a retain statement in > because I don't want to have to update the statement every month. What is a > good way of correctly ording the columns? > > > >Thanks, > >Dave >

Back to: Top of message | Previous page | Main SAS-L page