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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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