BookmarkSubscribeRSS Feed
3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

SQL has no concept of row order, and the order is never guaranteed. 

Use a data step instead.

For SQL, this not-recommended code might help:

proc sql;
  select monotonic() as M, mod(calculated M, 2) as ODD
  from SASHELP.CLASS;
quit;

 

Jagadishkatam
Amethyst | Level 16

Please try the below code with mod function to generate the odd and even row tables by proc sql

 

proc sql;
create table odd as SELECT * FROM (select *, monotonic() as row from sashelp.class ) where mod(row,2)<>0;
create table even as SELECT * FROM (select *, monotonic() as row from sashelp.class ) where mod(row,2)=0;
quit;
Thanks,
Jag
ballardw
Super User

What does your input look like, or an example, and what should the output look like?

There can be more than one interpretation of your subject line.

It could be "is the record order value even/odd"

It could be the record number is even/odd (not always the same thing with deleted information)

Is the value of some variable, or combination of variables even/odd.

Is the explicit value of some variable (or variables) the text "even" or "odd".

 

And I suspect that if I spent some time I might come up with a few more. So something specific might be a good idea.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 3025 views
  • 4 likes
  • 4 in conversation