Hi everyone,
I have a dataset in the first table and i have to retain values from the previous row to blank rows. How can i do that? Thanks in advance
Identifier | Date | NPO_Order | NPO_OrderedInstant |
112 | 2/2/2023 | NPO DIET | 02FEB23:22:48:00 |
112 | 2/3/2023 | . | |
112 | 2/4/2023 | NPO DIET | 04FEB23:07:24:00 |
112 | 2/5/2023 | . | |
112 | 2/6/2023 | DIET TUBE FEEDING ONLY (NPO) | 06FEB23:06:43:00 |
112 | 2/6/2023 | DIET TUBE FEEDING ONLY (NPO) | 06FEB23:07:52:00 |
112 | 2/7/2023 | NPO DIET | 07FEB23:17:06:00 |
112 | 2/8/2023 | . | |
112 | 2/9/2023 | . | |
112 | 2/10/2023 | DIET TUBE FEEDING ONLY (NPO) | 10FEB23:09:41:00 |
113 | 2/10/2023 | DIET TUBE FEEDING ONLY (NPO) | 10FEB23:09:54:00 |
113 | 2/10/2023 | DIET TUBE FEEDING ONLY (NPO) | 10FEB23:10:27:00 |
113 | 2/10/2023 | DIET TUBE FEEDING ONLY (NPO) | 10FEB23:10:27:00 |
113 | 2/10/2023 | NPO DIET | 10FEB23:13:48:00 |
113 | 2/11/2023 | ||
113 | 2/12/2023 | . | |
113 | 2/13/2023 | DIET TUBE FEEDING ONLY (NPO) | 13FEB23:09:14:00 |
113 | 2/14/2023 | . | |
113 | 2/15/2023 | DIET TUBE FEEDING ONLY (NPO) | 15FEB23:09:44:00 |
113 | 2/16/2023 | DIET TUBE FEEDING ONLY (NPO) | 16FEB23:08:46:00 |
113 | 2/17/2023 | DIET TUBE FEEDING ONLY (NPO) | 17FEB23:10:06:00 |
113 | 2/18/2023 | DIET TUBE FEEDING ONLY (NPO) | 18FEB23:07:59:00 |
Identifier | Date | NPO_Order | NPO_OrderedInstant |
112 | 2/2/2023 | NPO DIET | 02FEB23:22:48:00 |
112 | 2/3/2023 | NPO DIET | 02FEB23:22:48:00 |
112 | 2/4/2023 | NPO DIET | 04FEB23:07:24:00 |
112 | 2/5/2023 | NPO DIET | 04FEB23:07:24:00 |
112 | 2/6/2023 | DIET TUBE FEEDING ONLY (NPO) | 06FEB23:06:43:00 |
112 | 2/6/2023 | DIET TUBE FEEDING ONLY (NPO) | 06FEB23:07:52:00 |
112 | 2/7/2023 | NPO DIET | 07FEB23:17:06:00 |
112 | 2/8/2023 | NPO DIET | 07FEB23:17:06:00 |
112 | 2/9/2023 | NPO DIET | 07FEB23:17:06:00 |
112 | 2/10/2023 | DIET TUBE FEEDING ONLY (NPO) | 10FEB23:09:41:00 |
113 | 2/10/2023 | DIET TUBE FEEDING ONLY (NPO) | 10FEB23:09:54:00 |
113 | 2/10/2023 | DIET TUBE FEEDING ONLY (NPO) | 10FEB23:10:27:00 |
113 | 2/10/2023 | DIET TUBE FEEDING ONLY (NPO) | 10FEB23:10:27:00 |
113 | 2/10/2023 | NPO DIET | 10FEB23:13:48:00 |
113 | 2/11/2023 | NPO DIET | 10FEB23:13:48:00 |
113 | 2/12/2023 | NPO DIET | 10FEB23:13:48:00 |
113 | 2/13/2023 | DIET TUBE FEEDING ONLY (NPO) | 13FEB23:09:14:00 |
113 | 2/14/2023 | DIET TUBE FEEDING ONLY (NPO) | 13FEB23:09:14:00 |
113 | 2/15/2023 | DIET TUBE FEEDING ONLY (NPO) | 15FEB23:09:44:00 |
113 | 2/16/2023 | DIET TUBE FEEDING ONLY (NPO) | 16FEB23:08:46:00 |
113 | 2/17/2023 | DIET TUBE FEEDING ONLY (NPO) | 17FEB23:10:06:00 |
113 | 2/18/2023 | DIET TUBE FEEDING ONLY (NPO) | 18FEB23:07:59:00 |
Please help us by modifying the subject on your original message to "Retain values down columns"
data want;
set have;
retain npo_orderedinstant1;
if not missing(npo_orderedinstant) then npo_orderedinstant1=npo_orderedinstant;
run;
You can do the same thing for variable npo_order, so I leave that as a homework assignment for you.
Please help us by modifying the subject on your original message to "Retain values down columns"
data want;
set have;
retain npo_orderedinstant1;
if not missing(npo_orderedinstant) then npo_orderedinstant1=npo_orderedinstant;
run;
You can do the same thing for variable npo_order, so I leave that as a homework assignment for you.
Search for methods to implement Last Observation Carried Forward (LOCF).
You can normally do this very easily by using the UPDATE statement to treat the data as a series of transactions. Include an OUTPUT statement to preserve the individual observations instead of just the final result of applying all of the transactions.
data want;
update have(obs=0) have;
by identifier;
output;
run;
Thank you, i will look into that
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!
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.