Help using Base SAS procedures

Reg:Sort

Reply
Regular Contributor
Posts: 229

Reg:Sort

i am running a dataset the sort out put is taking alphabetically
data x3;
input d$;
cards;
jan07
feb07
aug07
aug06
feb06
run;
proc sort data=x3;
by d;
run;


i want the output like this

feb06
aug06
jan07
feb07
aug07


but it is comming like this
aug06
aug07
feb06
feb07
jan07

can u give any idea
Super Contributor
Posts: 273

Re: Reg:Sort

you have to change your d a character variable into a dn a numeric date
like this

data x3;
input d $;
dn=input(d,monyy5.);
cards;
jan07
feb07
aug07
aug06
feb06
run;
proc sort data=x3;
by dn;
run;
N/A
Posts: 0

Re: Reg:Sort

You read your values as characters, so SAS sorts them as characters...
You can import them as dates :
[pre]
data x3 ;
input d ANYDTDTE10. ;
format d MONYY. ;
cards ;
jan07
feb07
aug07
aug06
feb06
run ;

proc sort data = x3 ;
by d ;
run ;

proc print data = x3 noObs ;
title "Ordered Dates" ;
run ;
[/pre]
Ask a Question
Discussion stats
  • 2 replies
  • 115 views
  • 0 likes
  • 3 in conversation