BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tekish
Quartz | Level 8

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,

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

 

 

View solution in original post

8 REPLIES 8
Reeza
Super User

Use the MOD() function.

tekish
Quartz | Level 8

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,

 

Reeza
Super User

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

tekish
Quartz | Level 8

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
Reeza
Super User

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

 

 

tekish
Quartz | Level 8

I am trying to divide by 2.

tekish
Quartz | Level 8

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
Reeza
Super User

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;

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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