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
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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.