Building models with SAS Enterprise Miner, SAS Factory Miner, SAS Visual Data Mining and Machine Learning or just with programming

transponse time period

Reply
N/A
Posts: 1

transponse time period

Please advise...I need to transponse time period (format YYYYMM) by an ascending sequence. But I always become transposed result such a: 201201, 201203, 201103, 201204,... What should I do to get the ascending time period?

example of column:

Period

201203

201204

201106

201201

201103



Respected Advisor
Posts: 4,649

Re: transponse time period

Proc Transpose creates new variables in the order that it finds the id values in your dataset. One way to get what you want is to make sure that your first by-group contains all the id values in ascending sequence (by adding missing value observations if necessary). Another way is to reorder the columns after transposition with a datastep where the variables are named in ascending order in a RETAIN statement.

PG

PG
Super Contributor
Posts: 1,636

Re: transponse time period

Is this what you want?

data have;

informat period yymmn6.;

format period yymmn6.;

input period;

cards;

201203

201204

201106

201201

201103

;

proc transpose data=have out=want(drop=_Smiley Happy prefix=period;

var period;

run;

data want;

  set want;

  call sortn (of pSmiley Happy;

  run;

proc print;run;

             Obs    period1    period2    period3    period4    period5

             1       201103     201106     201201     201203     201204

Linlin

Ask a Question
Discussion stats
  • 2 replies
  • 192 views
  • 0 likes
  • 3 in conversation