how to insert values in new variable from existing variables?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

how to insert values in new variable from existing variables?

Hi All;

I’m  having trouble with inserting values in new variable(INC1 ,AZC1) from existing variable(INC,AZC) values , Initial values  for INC1 , AZC1 was ‘0’  and as previous date (INC & AZC )values  was next  INC1 &AZC1 values  like below mention , can anyone help me?

Date                   INC      AZC     INC1    AZC1 

10aug2014         0.254     0.145     0           0

14aug2014         1.457     2.14     0.254   0.145

15aug2014          2.145    1.245   1.457    2.14

19sep2014        1.874      1.547   2.145   1.245

21sep2014        1.198      0.587   1.874   1.547


Accepted Solutions
Solution
‎12-18-2014 09:34 AM
PROC Star
Posts: 7,436

Re: how to insert values in new variable from existing variables?

data have;

  input Date date9. INC      AZC     wINC1    wAZC1;

  inc1=coalesce(lag(inc),0);

  azc1=coalesce(lag(azc),0);

  cards;

10aug2014         0.254     0.145     0           0

14aug2014         1.457     2.14     0.254   0.145

15aug2014          2.145    1.245   1.457    2.14

19sep2014        1.874      1.547   2.145   1.245

21sep2014        1.198      0.587   1.874   1.547

;

View solution in original post


All Replies
Solution
‎12-18-2014 09:34 AM
PROC Star
Posts: 7,436

Re: how to insert values in new variable from existing variables?

data have;

  input Date date9. INC      AZC     wINC1    wAZC1;

  inc1=coalesce(lag(inc),0);

  azc1=coalesce(lag(azc),0);

  cards;

10aug2014         0.254     0.145     0           0

14aug2014         1.457     2.14     0.254   0.145

15aug2014          2.145    1.245   1.457    2.14

19sep2014        1.874      1.547   2.145   1.245

21sep2014        1.198      0.587   1.874   1.547

;

PROC Star
Posts: 7,436

Re: how to insert values in new variable from existing variables?

lag was used to get the previous record's value. Since you wanted 0 if there wasn't a previous value, both lag and coalesce were used.

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 294 views
  • 4 likes
  • 2 in conversation