Name | Sex | Age | Height | Weight |
Alfred | M | 14 | 69 | 112.5 |
Alice | F | 13 | 56.5 | 84 |
Barbara | F | 13 | 65.3 | 98 |
Carol | F | 14 | 62.8 | 102.5 |
Henry | M | 14 | 63.5 | 102.5 |
James | M | 12 | 57.3 | . |
Jane | F | 12 | 59.8 | . |
Janet | F | 15 | 62.5 | 112.5 |
Jeffrey | M | 13 | 62.5 | 84 |
John | M | 12 | 59 | . |
Joyce | F | 11 | 51.3 | 50.5 |
Judy | F | 14 | 64.3 | 90 |
Louise | F | 12 | 56.3 | . |
Mary | F | 15 | 66.5 | 112 |
Philip | M | 16 | 72 | 150 |
Robert | M | 12 | 64.8 | . |
Ronald | M | 15 | 67 | 133 |
Thomas | M | 11 | 57.5 | 85 |
William | M | 15 | 66.5 | 112 |
in above data weight variable has some missings so we use locf method and fill up missing values and the same time assign dtype=locf like below table
new_weight | Name | Sex | Age | Height | Weight | dtype |
112.5 | Alfred | M | 14 | 69 | 112.5 |
|
84 | Alice | F | 13 | 56.5 | 84 |
|
98 | Barbara | F | 13 | 65.3 | 98 |
|
102.5 | Carol | F | 14 | 62.8 | 102.5 |
|
102.5 | Henry | M | 14 | 63.5 | 102.5 |
|
102.5 | James | M | 12 | 57.3 | . | locf |
102.5 | Jane | F | 12 | 59.8 | . | locf |
112.5 | Janet | F | 15 | 62.5 | 112.5 |
|
84 | Jeffrey | M | 13 | 62.5 | 84 |
|
84 | John | M | 12 | 59 | . | locf |
50.5 | Joyce | F | 11 | 51.3 | 50.5 |
|
90 | Judy | F | 14 | 64.3 | 90 |
|
90 | Louise | F | 12 | 56.3 | . | locf |
112 | Mary | F | 15 | 66.5 | 112 |
|
150 | Philip | M | 16 | 72 | 150 |
|
150 | Robert | M | 12 | 64.8 | . | locf |
133 | Ronald | M | 15 | 67 | 133 |
|
85 | Thomas | M | 11 | 57.5 | 85 |
|
112 | William | M | 15 | 66.5 | 112 |
|
Please post test data in the form of a datastep and clearly describe what it is you are asking. From what you have posted:
data want; set have; dtype="locf"; run;
Gets you the second table, although this isn't what you are wanting is it. Maybe something like:
data want (drop=weight rename=(new_weight=weight)); set have; retain new_weight; if weight ne . then new_weight=weight; else dtype="locf"; run;
Not tested as no test data.
?
Are you asking how to implement locf?
The paper http://www2.sas.com/proceedings/sugi28/099-28.pdf seems to contain a description on how to implement locf.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: