Adding observations to an increasing variable, keeping three variables constant...

Accepted Solution Solved
Reply
Contributor
Posts: 25
Accepted Solution

Adding observations to an increasing variable, keeping three variables constant...

Hi! I have been googling this problem for a while, but the main problem is that I don't quite know what to "ask" for!

Thus, so far my search have been unsuccessful. Hopefully someone here can help me!?

I have a dataset “data1” that looks like this:

ID

A

B

C

day

1

0.45

2

30

0

2

0.55

2

31

0

3

0.5

2

30

0

I want to add 4 new observations/rows (days) per individual, but the 3 variables: A, B and C must be constant.

The new dataset “data2” should look like this:

ID

A

B

C

day

1

0.45

2

30

0

1

0.45

2

30

1

1

0.45

2

30

2

1

0.45

2

30

3

1

0.45

2

30

4

2

0.55

2

31

0

2

0.55

2

31

1

2

0.55

2

31

2

2

0.55

2

31

3

2

0.55

2

31

4

3

0.5

2

30

1

3

0.5

2

30

2

3

0.5

2

30

3

3

0.5

2

30

0

3

0.5

2

30

4

(In "real life" my data1 consists of 2500 individuals (ID) with one observation each, and in total each individual should have 1000 new observations/rows, so I need a solution that is applicable to thees sizes...)


Accepted Solutions
Solution
‎06-04-2014 04:07 AM
Super Contributor
Posts: 297

Re: Adding observations to an increasing variable, keeping three variables constant...

Posted in reply to Kristinos

Hi Kristinos,

Will day always contain 0 in the data1 dataset?

If so, you could use a do loop.

DATA WANT;

  SET HAVE (DROP = DAY);

  DO DAY = 0 TO 4;

  OUTPUT;

  END;

RUN;

View solution in original post


All Replies
Solution
‎06-04-2014 04:07 AM
Super Contributor
Posts: 297

Re: Adding observations to an increasing variable, keeping three variables constant...

Posted in reply to Kristinos

Hi Kristinos,

Will day always contain 0 in the data1 dataset?

If so, you could use a do loop.

DATA WANT;

  SET HAVE (DROP = DAY);

  DO DAY = 0 TO 4;

  OUTPUT;

  END;

RUN;

Contributor
Posts: 25

Re: Adding observations to an increasing variable, keeping three variables constant...

Posted in reply to Scott_Mitchell

Yes, day will always contain 0, so this worked!!

Thank you so much! (I don't understand why I haven't tried this forum before...

Super Contributor
Posts: 297

Re: Adding observations to an increasing variable, keeping three variables constant...

Posted in reply to Kristinos

Glad I could help.

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 219 views
  • 1 like
  • 2 in conversation