Search code examples
sasenterprise-guide

Split a row into multiple rows in SAS enterprise guide


I need help to split a row into multiple rows when the value on the row is something like 1-5. The reason is that I need to count 1-5 to become 5, and not 1, as it is when it count on one row.

I've a ID, the value and where it belong.

As exempel:

ID  Value Page
1    1-5   2

The output I want is something like this:

ID Value Page
1    1    2
1    2    2
1    3    2
1    4    2
1    5    2

I've tried using a IF-statement

IF bioVerdi='1-5' THEN
        DO;
            ..
        END;

So I don't know what I should put between the DO; and END;. Any clues to help me out here?


Solution

  • You need to loop over the values inside your range and OUTPUT the values. The OUTPUT statement causes the Data Step to write a record to the output data set.

    data want;
    set have;
    if bioVerdi = '1-5' then do;
       do value=1 to 5;
          output;
       end;
    end;