BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
meckarthik
Quartz | Level 8

Hi, need help!

got a scenario, where need to populate the same record for above and below the value 1 and value 2 records  until it got the same ID or value 1 or value 2 is not empty

IDDate Value1Value2
114-Oct-17..
115-Oct-17..
116-Oct-17..
117-Oct-17..
118-Oct-17..
119-Oct-1712
120-Oct-17..
121-Oct-17..
122-Oct-1725
123-Oct-17..
124-Oct-17..
214-Oct-17..
215-Oct-17..
216-Oct-17..
217-Oct-1746
218-Oct-17..
219-Oct-17..
220-Oct-17..
221-Oct-17..
222-Oct-17..

 

 

I want something like 

IDDate Value1Value2
114-Oct-1712
115-Oct-1712
116-Oct-1712
117-Oct-1712
118-Oct-1712
119-Oct-1712
120-Oct-1712
121-Oct-1712
122-Oct-1725
123-Oct-1725
124-Oct-1725
214-Oct-1746
215-Oct-1746
216-Oct-1746
217-Oct-1746
218-Oct-1746
219-Oct-1746
220-Oct-1746
221-Oct-1746
222-Oct-1746
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

A little sorting and updating does the trick 🙂

 

data have;
input ID	Date:date11. 	Value1	Value2;
format Date date11.;
datalines;
1	14-Oct-17	.	.
1	15-Oct-17	.	.
1	16-Oct-17	.	.
1	17-Oct-17	.	.
1	18-Oct-17	.	.
1	19-Oct-17	1	2
1	20-Oct-17	.	.
1	21-Oct-17	.	.
1	22-Oct-17	2	5
1	23-Oct-17	.	.
1	24-Oct-17	.	.
2	14-Oct-17	.	.
2	15-Oct-17	.	.
2	16-Oct-17	.	.
2	17-Oct-17	4	6
2	18-Oct-17	.	.
2	19-Oct-17	.	.
2	20-Oct-17	.	.
2	21-Oct-17	.	.
2	22-Oct-17	.	.
;

data temp;
   update have(obs=0) have;
   by ID;
   output;
run;

proc sort data=temp;
   by ID descending Date; 
run;

data temp2;
   update temp(obs=0) temp;
   by ID;
   output;
run;

proc sort data=temp2 out=want;
   by ID Date; 
run;

proc datasets lib=work nolist;
   delete temp:;
run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

A little sorting and updating does the trick 🙂

 

data have;
input ID	Date:date11. 	Value1	Value2;
format Date date11.;
datalines;
1	14-Oct-17	.	.
1	15-Oct-17	.	.
1	16-Oct-17	.	.
1	17-Oct-17	.	.
1	18-Oct-17	.	.
1	19-Oct-17	1	2
1	20-Oct-17	.	.
1	21-Oct-17	.	.
1	22-Oct-17	2	5
1	23-Oct-17	.	.
1	24-Oct-17	.	.
2	14-Oct-17	.	.
2	15-Oct-17	.	.
2	16-Oct-17	.	.
2	17-Oct-17	4	6
2	18-Oct-17	.	.
2	19-Oct-17	.	.
2	20-Oct-17	.	.
2	21-Oct-17	.	.
2	22-Oct-17	.	.
;

data temp;
   update have(obs=0) have;
   by ID;
   output;
run;

proc sort data=temp;
   by ID descending Date; 
run;

data temp2;
   update temp(obs=0) temp;
   by ID;
   output;
run;

proc sort data=temp2 out=want;
   by ID Date; 
run;

proc datasets lib=work nolist;
   delete temp:;
run;
meckarthik
Quartz | Level 8

It works! Thank you!

PeterClemmensen
Tourmaline | Level 20

No problem, glad to help 🙂

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 665 views
  • 2 likes
  • 2 in conversation