DATA Step, Macro, Functions and more

Reorder the rownumber

Accepted Solution Solved
Reply
Contributor
Posts: 55
Accepted Solution

Reorder the rownumber

Exeperts,

 

I have huge dataset and I want to reorder my row number 1-6.how do I order when I don't have other variable to group.

 

here is the sample SAS program:

 

data want;

set sashelp.class;

rownum=_n_;

newvalue=mod(rownum,2);

run;

 

Here is the expected output:

NameSexAgeHeightWeightrownumnewvalue
AlfredM1469.0112.511
AliceF1356.584.022
BarbaraF1365.398.033
CarolF1462.8102.544
HenryM1463.5102.555
JamesM1257.383.066
JaneF1259.884.571
JanetF1562.5112.582
JeffreyM1362.584.093
JohnM1259.099.5104
JoyceF1151.350.5115
JudyF1464.390.0126
LouiseF1256.377.0131
MaryF1566.5112.0142
PhilipM1672.0150.0153
RobertM1264.8128.0164
RonaldM1567.0133.0175
ThomasM1157.585.0186
WilliamM1566.5112.0191

 

 

Appreciate your help.

 

thanks,

 


Accepted Solutions
Solution
‎10-20-2017 11:37 AM
Super User
Posts: 19,815

Re: Reorder the rownumber

Why are you using 2 in the MOD() function?

 

 

View solution in original post


All Replies
Super User
Posts: 19,815

Re: Reorder the rownumber

Use the MOD() function.

Contributor
Posts: 55

Re: Reorder the rownumber

Reeza,

 

I am using MOD() function but I am getting 1 and 0.

 

if you don't mind could you please add your code to example above.

 

thanks,

 

Super User
Posts: 19,815

Re: Reorder the rownumber

Post what you've tried and I'm happy to help.

Contributor
Posts: 55

Re: Reorder the rownumber

When I this:

data want;

set sashelp.class;

rownum=_n_;

newvalue=mod(rownum,2);

run;

 

I got this one.

 

NameSexAgeHeightWeightrownumnewvalue
AlfredM1469.0112.511
AliceF1356.584.020
BarbaraF1365.398.031
CarolF1462.8102.540
HenryM1463.5102.551
JamesM1257.383.060
JaneF1259.884.571
JanetF1562.5112.580
JeffreyM1362.584.091
JohnM1259.099.5100
JoyceF1151.350.5111
JudyF1464.390.0120
LouiseF1256.377.0131
MaryF1566.5112.0140
PhilipM1672.0150.0151
RobertM1264.8128.0160
RonaldM1567.0133.0171
ThomasM1157.585.0180
WilliamM1566.5112.0191
Solution
‎10-20-2017 11:37 AM
Super User
Posts: 19,815

Re: Reorder the rownumber

Why are you using 2 in the MOD() function?

 

 

Contributor
Posts: 55

Re: Reorder the rownumber

I am trying to divide by 2.

Contributor
Posts: 55

Re: Reorder the rownumber

Reeza,

 

data want;

set sashelp.class;

rownum=_n_;

newvalue=mod(rownum,6);

run;

 

NameSexAgeHeightWeightrownumnewvalue
AlfredM1469.0112.511
AliceF1356.584.022
BarbaraF1365.398.033
CarolF1462.8102.544
HenryM1463.5102.555
JamesM1257.383.060
JaneF1259.884.571
JanetF1562.5112.582
JeffreyM1362.584.093
JohnM1259.099.5104
JoyceF1151.350.5115
JudyF1464.390.0120
LouiseF1256.377.0131
MaryF1566.5112.0142
PhilipM1672.0150.0153
RobertM1264.8128.0164
RonaldM1567.0133.0175
ThomasM1157.585.0180
WilliamM1566.5112.0191
Super User
Posts: 19,815

Re: Reorder the rownumber

So all you need now is to change the 0's to 6's. 

 

Or you can muck around a bit more with the MOD function which ends up something like:

 

 

x= mod(i-1, 6)+1;

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 112 views
  • 1 like
  • 2 in conversation