BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jaiganesh
Obsidian | Level 7

Reverse the order of data without sorting.

 

Dataset –
var1
7
1
6
4
3
8

 

Output –
var1
8
3
4
6
1
7



Please suggest code to print above output with data statement not with sql.

 

 

Regards,

Jai

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Or use the POINT= option of the SET statement:

data _null_;
file print;
put 'var1';
do i=n to 1 by -1;
  set have nobs=n point=i;
  put var1;
end;
stop;
run;

 

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Please suggest code to print above output with data statement not with sql.

 

How about using PROC SORT????

 

data want;
    set have;
    seq=_n_;
run;
proc sort data=want;
    by descending seq;
run;

 

 

 

--
Paige Miller
FreelanceReinh
Jade | Level 19

Or use the POINT= option of the SET statement:

data _null_;
file print;
put 'var1';
do i=n to 1 by -1;
  set have nobs=n point=i;
  put var1;
end;
stop;
run;

 

novinosrin
Tourmaline | Level 20

Of course when genie_reinhard has answered, others can retire but so bored today

 

 


data have;
input var1;
cards;
7
1
6
4
3
8
;

data _null_;
if _n_=1 then do;
   dcl hash H (ordered: "d") ;
   h.definekey  ("_n_") ;
   h.definedata ("var1") ;
   h.definedone () ;
  end;
  set have end=lr;
  rc=h.add();
if lr then h.output(dataset:'want');
run;

 

 

 

ballardw
Super User

And likely not to be terribly efficient or generalizable but

data have;
input var1;
datalines;
7
1
6
4
3
8
;
run;

proc transpose data=have out=want;
run;

data _null_;
   set want;
   file print;
   array c col: ;
   do i= dim(c) to 1 by -1;
     put c[i];
   end;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1376 views
  • 0 likes
  • 5 in conversation