Hi there,
could you please help?
I have missing entries for ID and PACIENTE in Excel like:
ID | PACIENTE | FECHA | TSH | T4 | T3 | TIROG |
0125168-01 | JOHN SMITH | 11-nov-13 | 0.023 | 11.84 | 1.34 | <0.10 |
12-nov-13 | 63.71 | 11.61 | 1.3 | 0.268 |
and would like fill blanks with the info (CLAVE AND PACIENTE) above like :
CLAVE | PACIENTE | FECHA | TSH | T4 | T3 | TIROG |
0125168-01 | John Smith | 11-nov-13 | 0.023 | 11.84 | 1.34 | <0.10 |
0125168-01 | John Smith | 12-nov-13 | 63.71 | 11.61 | 1.3 | 0.268 |
in some cases there are more than one blank row (3 or 4) with different "FECHA"
all your help will be apprecitated
Thanks
Once you have a SAS dataset, do
data want;
set have;
retain _id _paciente;
if missing(id)
then id = _id;
else _id = id;
if missing(paciente)
then paciente = _paciente;
else _paciente = paciente;
drop _id _paciente;
run;
Hi there,
could you please help?
I have missing entries for ID and PACIENTE in Excel like:
ID | PACIENTE | FECHA | TSH | T4 | T3 | TIROG |
0125168-01 | JOHN SMITH | 11-nov-13 | 0.023 | 11.84 | 1.34 | <0.10 |
12-nov-13 | 63.71 | 11.61 | 1.3 | 0.268 |
and would like fill blanks with the info (CLAVE AND PACIENTE) above like :
CLAVE | PACIENTE | FECHA | TSH | T4 | T3 | TIROG |
0125168-01 | John Smith | 11-nov-13 | 0.023 | 11.84 | 1.34 | <0.10 |
0125168-01 | John Smith | 12-nov-13 | 63.71 | 11.61 | 1.3 | 0.268 |
in some cases there are more than one blank row (3 or 4) with different "FECHA"
all your help will be apprecitated
Thanks
So if you have missing values, you wish to replace these with the last nonmissing value? 🙂
And is CLAVE just a renamed version of ID?
Hi Draycut,
Yes! and Yes!
the code tha KurtBremser sent me worked just fine, but thanks anyway. All your help is very much appreciated
lalohg
Once you have a SAS dataset, do
data want;
set have;
retain _id _paciente;
if missing(id)
then id = _id;
else _id = id;
if missing(paciente)
then paciente = _paciente;
else _paciente = paciente;
drop _id _paciente;
run;
I did not try test this - and I think the data you've shown is probably too incomplete to test it accurately - but here's one approach.
The initial sorting might not be needed, but it will get the non-missing to appear first. Then use a retain to carry the non-missing observations over to the missing.
proc sort data = have;
by descending id descending paciente fecha;
run;
data want;
retain clave paciente2;
set have;
if not missing(id) then clave = id;
if not missing(paciente) then paciente2 = paciente;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.