-2

I am working on a project where I need to specify the order of objects in the data for a custom SAS report. I am having trouble with something that should be easy, here is an example of the data I am working with.

obs   ord   ord2  name
  1     3      1    A
  2     3      .    B
  3     3      .    C
  4     3      .    D
  5     4      1    E
  6     4      .    F
  7     5      1    G
  8     5      .    H
  9     5      .    I
 10     5      .    J

What I'd like is...

    obs   ord   ord2  name
      1     3      1    A
      2     3      2    B
      3     3      3    C
      4     3      4    D
      5     4      1    E
      6     4      2    F
      7     5      1    G
      8     5      2    H
      9     5      3    I
     10     5      4    J

So that for every first occurrence of ord, ord2 = 1,...,n_i.

Thanks for the help!

k6adams
  • 406
  • 1
  • 3
  • 12
  • How about doing this step on the original data? It is relatively easier to manipulate using data step. – Robbie Liu Dec 04 '14 at 05:08
  • @RobbieLiu that might be even more difficult, unfortunately I need to produce a table that looks like this... http://www.stat.wmich.edu/wang/680/docs/aetest.lst – k6adams Dec 04 '14 at 05:29
  • If the original data set looks like what you have shown here, the order number can be added using data step. Then you can use ′proc report´ to customize report. Is that right? – Robbie Liu Dec 04 '14 at 05:40
  • @RobbieLiu here is what the original data looks like... https://drive.google.com/file/d/0B-A7YPjHrXqNMjY3TFFsd0lVZkE/view?usp=sharing – k6adams Dec 04 '14 at 05:53
  • @RobbieLiu here is what I have... https://drive.google.com/file/d/0B-A7YPjHrXqNR3Z5czBsREhrMDg/view?usp=sharing this is what I want... https://drive.google.com/file/d/0B-A7YPjHrXqNM2xUeEJlQkhNek0/view?usp=sharing – k6adams Dec 04 '14 at 05:59
  • Please do not attach files via google drive. Include sufficient code in your question _in text_ for it to be answerable. – Joe Dec 04 '14 at 15:26
  • @joe I think that my question could have been understood without the images, I only chose to include images in response to the particular questions in the comments. Would you have another suggestion for posting codes and examples in the comments? – k6adams Dec 04 '14 at 15:36
  • 1
    Look at the various other questions on this site. Post code and examples _as text_, not as images. If it's not short enough to post as text, it's probably not a good question. You didn't include your proc report code in the question, which made this a "write code for me" question - which is strongly discouraged. – Joe Dec 04 '14 at 15:37

1 Answers1

1

Just apply a group numbering to the original data set, provided that the table has been sorted by ord.

data table1;
   set table1;
   by ord;
   ord2_ + 1;
   if first.ord then ord2_ = 1;
   drop ord2;
   rename ord2_=ord2;
Run;
Robbie Liu
  • 1,511
  • 1
  • 11
  • 16
  • thanks for the suggestion but it didn't seem to work. here is the code, https://drive.google.com/file/d/0B-A7YPjHrXqNSHJUQUhqNzdDQmc/view?usp=sharing here is what it produced... https://drive.google.com/file/d/0B-A7YPjHrXqNN3ZBcjFpd3FnaXc/view?usp=sharing – k6adams Dec 04 '14 at 06:20
  • @k6adams I forgot that your table already has `ord2`. So just create a new serial then rename. – Robbie Liu Dec 04 '14 at 06:33