BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Costasg
Calcite | Level 5

Hello All,

I am new to SAS and I am facing a problem.

I have a database with three columns, Code,Date,Volume. Ihave them sorted by code and date. When I transpose the data and setting the dates as variables they get mixed. So instead of having _31DEC2001, _31JAN2002, _28FEB2002 and so on I get: _30APR2008, _31OCT2002, _31MAR2003 etc.

Is there any way to arrange the variables(columns) so they will be in the correct date order?

I am attaching a sample file

I am transposing it as follows:

proc transpose data=yuri out=yuri2;

by code;

id date;

var volume;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
NickR
Quartz | Level 8

As data_null_ said, creating dummy BY group values would help.

proc sql;

          create table yuri_ as select distinct date,0.1 as code from yuri;

quit;

 

data yuri2;

          set yuri yuri_;

run;

 

proc sort; by code date; run;

 

proc transpose data=yuri2 out=yuri3(where=(code^=0.1));

          by code;

          id date;

          var volume;

run;

View solution in original post

3 REPLIES 3
data_null__
Jade | Level 19

The variables, defined by the ID statement, are created in the same order new values of the ID variable are processed.  If the first CODE does not have all the dates then order of new vars may not be what you want/expect.  If the values of date are character they probably don't sort in data order, again not what you want.

I sometimes create a dummy BY group that has all the ID values in the order I prefer and use that to get the desired order.  You can search for other threads that address this issue and provide examples.

NickR
Quartz | Level 8

As data_null_ said, creating dummy BY group values would help.

proc sql;

          create table yuri_ as select distinct date,0.1 as code from yuri;

quit;

 

data yuri2;

          set yuri yuri_;

run;

 

proc sort; by code date; run;

 

proc transpose data=yuri2 out=yuri3(where=(code^=0.1));

          by code;

          id date;

          var volume;

run;

Costasg
Calcite | Level 5

Many thanks guys!

NickR it works great! You saved me lots of time.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 774 views
  • 3 likes
  • 3 in conversation