## creating new rows. based on existing rows

Solved
Frequent Contributor
Posts: 75

# creating new rows. based on existing rows

Hi, I have a time-series data of the following and I would like to add new id to the table using the existing id. How can i do this? Thank you very much.

date                    ID                    value

.....

01/31/1985          0-9               (6201-4183)

02/28/1985          0-9               (6505-4303)

...

Accepted Solutions
Solution
‎04-11-2013 03:59 PM
Super User
Posts: 6,762

## Re: creating new rows. based on existing rows

Well, if ID and VALUE are numeric variables, you will be limited as to what you place in there.  But here is an approach.

data want;

set have;

by date;

if first.date then do;

original_id = id;

original_value = value;

retain original_id original_value;

end;

output;

if last.date then do;

id = 90000 + 100 * original_id + id;

value = value - original_value;

output;

end;

drop original_id original_value;

run;

Good luck.

All Replies
Posts: 3,001

## Re: creating new rows. based on existing rows

data abc;

set abc;

output;

if id=0 or id=9 then output;

run;

--
Paige Miller
Frequent Contributor
Posts: 75

## Re: creating new rows. based on existing rows

Posted in reply to PaigeMiller

this one just duplicated the id number 0 and 9. I would like to create new id 10 that has the different of 0 and 9 as value

Super User
Posts: 13,523

## Re: creating new rows. based on existing rows

Is this what you want, assumes ID always has values of 0 through 9 AND value exists for each:

data want;

set have;

if ID = 9 then do;

output;

ID=10;

value=dif9(value);

output;

end;

else output;

run;

Solution
‎04-11-2013 03:59 PM
Super User
Posts: 6,762

## Re: creating new rows. based on existing rows

Well, if ID and VALUE are numeric variables, you will be limited as to what you place in there.  But here is an approach.

data want;

set have;

by date;

if first.date then do;

original_id = id;

original_value = value;

retain original_id original_value;

end;

output;

if last.date then do;

id = 90000 + 100 * original_id + id;

value = value - original_value;

output;

end;

drop original_id original_value;

run;

Good luck.

Frequent Contributor
Posts: 75

## Re: creating new rows. based on existing rows

Posted in reply to Astounding

Thanks!.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
• 5 replies
• 213 views
• 0 likes
• 4 in conversation