BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
thdang
Calcite | Level 5

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)

...

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

data abc;

    set abc;

    output;

    if id=0 or id=9 then output;

run;

--
Paige Miller
thdang
Calcite | Level 5

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

ballardw
Super User

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;

Astounding
PROC Star

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.

thdang
Calcite | Level 5

Thanks!.

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!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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