BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aayushi_17
Quartz | Level 8
How can I select rows in reverse order?

For example I have a column sample1 which has values like. This

Sample1

1
2
A
Sr
R
Y
7

The output I want is :

7
Y
R
Sr
A
2
1


I anyone knows please help me.. Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

And if you do NOT mind a NOTE in the log stating "NOTE: The query as specified involves ordering by an item that doesn't appear in its SELECTclause."

 

data have;
input var $;
cards;
1
2
A
Sr
R
Y
7
;

proc sql;
create table want as
select *
from have
order by monotonic()  desc;
quit;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20
data have;
input var $;
cards;
1
2
A
Sr
R
Y
7
;

proc sql;
create table want(drop=rn) as
select *,monotonic() as rn
from have
order by rn desc;
quit;
novinosrin
Tourmaline | Level 20

And if you do NOT mind a NOTE in the log stating "NOTE: The query as specified involves ordering by an item that doesn't appear in its SELECTclause."

 

data have;
input var $;
cards;
1
2
A
Sr
R
Y
7
;

proc sql;
create table want as
select *
from have
order by monotonic()  desc;
quit;
Aayushi_17
Quartz | Level 8
Thank you... This worked
Ksharp
Super User

If your table is not very big.

 

data have;
input var $;
cards;
1
2
A
Sr
R
Y
7
;

data want;
 do i=nobs to 1 by -1;
  set have nobs=nobs point=i;
  output;
 end;
 stop;
 drop i;
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 2582 views
  • 3 likes
  • 3 in conversation