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
| ID | Date | Value1 | Value2 |
| 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 | . | . |
I want something like
| ID | Date | Value1 | Value2 |
| 1 | 14-Oct-17 | 1 | 2 |
| 1 | 15-Oct-17 | 1 | 2 |
| 1 | 16-Oct-17 | 1 | 2 |
| 1 | 17-Oct-17 | 1 | 2 |
| 1 | 18-Oct-17 | 1 | 2 |
| 1 | 19-Oct-17 | 1 | 2 |
| 1 | 20-Oct-17 | 1 | 2 |
| 1 | 21-Oct-17 | 1 | 2 |
| 1 | 22-Oct-17 | 2 | 5 |
| 1 | 23-Oct-17 | 2 | 5 |
| 1 | 24-Oct-17 | 2 | 5 |
| 2 | 14-Oct-17 | 4 | 6 |
| 2 | 15-Oct-17 | 4 | 6 |
| 2 | 16-Oct-17 | 4 | 6 |
| 2 | 17-Oct-17 | 4 | 6 |
| 2 | 18-Oct-17 | 4 | 6 |
| 2 | 19-Oct-17 | 4 | 6 |
| 2 | 20-Oct-17 | 4 | 6 |
| 2 | 21-Oct-17 | 4 | 6 |
| 2 | 22-Oct-17 | 4 | 6 |
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;
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;
It works! Thank you!
No problem, glad to help 🙂
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.