DATA Step, Macro, Functions and more

Having 2 Reqs for update on dates

Reply
Frequent Contributor
Posts: 140

Having 2 Reqs for update on dates

data std;
input id no sdate date9.;
format sdate date9.;
cards;
2 4 19JAN2012
3 5 19JAN2012
4 6 19JAN2012
5 7 19JAN2012
6 8 19JAN2012
run;


data change;
input id no sdate date9.;
format sdate date9.;
cards;
2 4 20JAN2012
3 5 20JAN2012
4 6 20JAN2012
5 9 20JAN2012
6 10 20JAN2012
7 11 20JAN2012
8 12 20JAN2012

;run;

Req  1:
--------

In the both above tables i want to append the observations from change to std table that are modified and not exesting
based on id and no


Output for table std

id no sdate
2 4 19JAN2012
3 5 19JAN2012
4 6 19JAN2012
5 7 19JAN2012
6 8 19JAN2012
5 9 20JAN2012
6 10 20JAN2012
7 11 20JAN2012
8 12 20JAN2012

Req 2:

--------

I want to create from table std new table called keep_change in this i want to keep the records that are changed based
on id and no and wnat new variable called endadte (The end date is nothing but the sdate on previous obs).

id no   sdate      endadte.
5   7  19JAN2012   20JAN2012
6   8  19JAN2012   20JAN2012

Super User
Posts: 9,681

Having 2 Reqs for update on dates

Emmmmm.....?

I remembered that I have coded it several days ago.

data std;
input id no sdate date9.;
format sdate date9.;
cards;
2 4 19JAN2012
3 5 19JAN2012
4 6 19JAN2012
5 7 19JAN2012
6 8 19JAN2012
;
run;


data change;
input id no sdate date9.;
format sdate date9.;
cards;
2 4 20JAN2012
3 5 20JAN2012
4 6 20JAN2012
5 9 20JAN2012
6 10 20JAN2012
7 11 20JAN2012
8 12 20JAN2012
;
run;
proc sql;
create table temp as
 select *
  from change
   where id not in (select distinct id from std) or  no not in (select distinct no from std) ;

create table want as
 select * from std
 union all corresponding
 select * from temp;

create table keep_change as
 select a.*, b.sdate as endadte
  from std as a,temp as b
   where a.id=b.id;
quit;


Ksharp

Ask a Question
Discussion stats
  • 1 reply
  • 118 views
  • 0 likes
  • 2 in conversation