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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1141 views
  • 1 like
  • 2 in conversation