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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

6 REPLIES 6
lalohg
Quartz | Level 8

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

 

PeterClemmensen
Tourmaline | Level 20

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?

lalohg
Quartz | Level 8

Hi Draycut,

 

Yes!  and Yes!

 

the code tha 

 

Kurt_Bremser
Super User

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;
lalohg
Quartz | Level 8

 

 

 

collinelliot
Barite | Level 11

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;

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1370 views
  • 1 like
  • 4 in conversation