BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Reeza
Super User

Where's the rest of the code? The sort and the row/group numbers as well?

tekish
Quartz | Level 8

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.

 

NameSexAgeHeightWeightrownumgroupneworder
AlfredM1469.0112.5111
BarbaraF1365.398.0312
HenryM1463.5102.5513
AliceF1356.584.0214
CarolF1462.8102.5415
JamesM1257.383.0616
JaneF1259.884.5721
JeffreyM1362.584.0922
JoyceF1151.350.51123
JanetF1562.5112.5824
JohnM1259.099.51025
JudyF1464.390.01226
LouiseF1256.377.01331
PhilipM1672.0150.01532
RonaldM1567.0133.01733
MaryF1566.5112.01434
RobertM1264.8128.01635
ThomasM1157.585.01836
WilliamM1566.5112.01941

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 16 replies
  • 3072 views
  • 3 likes
  • 2 in conversation