BookmarkSubscribeRSS Feed
sas_Forum
Calcite | Level 5

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

1 REPLY 1
Ksharp
Super User

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 973 views
  • 0 likes
  • 2 in conversation