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
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;
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;
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;
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;
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.