BookmarkSubscribeRSS Feed
holiska
Calcite | Level 5

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



2 REPLIES 2
PGStats
Opal | Level 21

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
Linlin
Lapis Lazuli | Level 10

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=_:) prefix=period;

var period;

run;

data want;

  set want;

  call sortn (of p:);

  run;

proc print;run;

             Obs    period1    period2    period3    period4    period5

             1       201103     201106     201201     201203     201204

Linlin

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!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 765 views
  • 0 likes
  • 3 in conversation