BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5
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
2 REPLIES 2
Andre
Obsidian | Level 7
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;
deleted_user
Not applicable
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]

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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