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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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