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
.....
want to add:
01/31/1985 0-9 (6201-4183)
02/28/1985 0-9 (6505-4303)
...
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.
data abc;
set abc;
output;
if id=0 or id=9 then output;
run;
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
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;
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.
Thanks!.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.