Where's the rest of the code? The sort and the row/group numbers as well?
Reeza,
It works when I added all the codes. Thank you for you help.
here is the final code.
data want;
set sashelp.class;
rownum=_n_;
if mod(_n_, 6) = 1 then group+1;
newvalue=mod(rownum,6);
if newvalue=0 then newvalue1=6;
else newvalue1=newvalue;
run;
data want1(drop=newvalue newvalue1);
set want;
if newvalue1=1 then neworder=1;
if newvalue1=2 then neworder=4;
if newvalue1=3 then neworder=2;
if newvalue1=4 then neworder=5;
if newvalue1=5 then neworder=3;
if newvalue1=6 then neworder=6;
run;
proc sort data=want1 out=test;
by group neworder;
run;
The expected output.
| Name | Sex | Age | Height | Weight | rownum | group | neworder |
| Alfred | M | 14 | 69.0 | 112.5 | 1 | 1 | 1 |
| Barbara | F | 13 | 65.3 | 98.0 | 3 | 1 | 2 |
| Henry | M | 14 | 63.5 | 102.5 | 5 | 1 | 3 |
| Alice | F | 13 | 56.5 | 84.0 | 2 | 1 | 4 |
| Carol | F | 14 | 62.8 | 102.5 | 4 | 1 | 5 |
| James | M | 12 | 57.3 | 83.0 | 6 | 1 | 6 |
| Jane | F | 12 | 59.8 | 84.5 | 7 | 2 | 1 |
| Jeffrey | M | 13 | 62.5 | 84.0 | 9 | 2 | 2 |
| Joyce | F | 11 | 51.3 | 50.5 | 11 | 2 | 3 |
| Janet | F | 15 | 62.5 | 112.5 | 8 | 2 | 4 |
| John | M | 12 | 59.0 | 99.5 | 10 | 2 | 5 |
| Judy | F | 14 | 64.3 | 90.0 | 12 | 2 | 6 |
| Louise | F | 12 | 56.3 | 77.0 | 13 | 3 | 1 |
| Philip | M | 16 | 72.0 | 150.0 | 15 | 3 | 2 |
| Ronald | M | 15 | 67.0 | 133.0 | 17 | 3 | 3 |
| Mary | F | 15 | 66.5 | 112.0 | 14 | 3 | 4 |
| Robert | M | 12 | 64.8 | 128.0 | 16 | 3 | 5 |
| Thomas | M | 11 | 57.5 | 85.0 | 18 | 3 | 6 |
| William | M | 15 | 66.5 | 112.0 | 19 | 4 | 1 |
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 save with the early bird rate—just $795!
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.