You would need to re-create the data set. And it's clumsy. This would be one way.
data want;
do until (done1);
set have (obs=14) end=done1;
output;
end;
set have (firstobs=83 obs=83);
output;
do until (done2);
set have (firstobs=16 obs=82) end=done2;
output;
end;
set have (firstobs=15 obs=15);
output;
do until (done3);
set have (firstobs=84) end=done3;
output;
end;
run;
This would be easier (less clumsy), but probably takes longer to run:
data want;
do _n_=1 to 14, 83, 16 to 82, 15, 84 to _nobs_;
set have nobs=_nobs_ point=_n_;
output;
end;
stop;
run;
The code is untested, but should be OK.
You may have to write a macro to swap row.
Thats not logical. Why the 15th and why the 83rd? You can do it by using the _n_ automatic variable but I would really advise against it as any change to that data (sorting, logic etc.) would mess up that change. You would be better off looking at why you select the 15th and 83rd rows and then use that selection criteria to pull out the rows you want and swap them over. Also bear in mind that there are sort procedures and such like that sort the data based on key variables, not position in the dataset. You may be thinking in Excel terms, don't, SAS datasets are logically ordered and manipulated.
You would need to re-create the data set. And it's clumsy. This would be one way.
data want;
do until (done1);
set have (obs=14) end=done1;
output;
end;
set have (firstobs=83 obs=83);
output;
do until (done2);
set have (firstobs=16 obs=82) end=done2;
output;
end;
set have (firstobs=15 obs=15);
output;
do until (done3);
set have (firstobs=84) end=done3;
output;
end;
run;
This would be easier (less clumsy), but probably takes longer to run:
data want;
do _n_=1 to 14, 83, 16 to 82, 15, 84 to _nobs_;
set have nobs=_nobs_ point=_n_;
output;
end;
stop;
run;
The code is untested, but should be OK.
hi
could you please explain a bit how POINT options is working here??
-Rahul
Point options make set statement to read data from observation number mentioned with point = .
Why not make a index variable N and proc sort it ? data have; do i=1 to 100; output; end; run; data want; set have; n=_n_; if n=15 then n=84; else if n=84 then n=15; run; proc sort data=want;by n;run;
@Ksharp Simple and very effective.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.