hi guys,
i need your help on this.
Here is my input file attached and i need to get the same output plus the missing values retained from the previous observations but my retain statement doesn't seem to be working .Anyone knows why?
Thanks,
data one;
infile 'C:\Users\Trajce\Contacts\Desktop\test.txt';
input id $3. gender $1. dob mmddyy8. visit 1. h3 3. sbp 3. dbp 3.;
retain gender dob ;
format dob mmddyy8.;
This should suffice. If you have more variables there is and easier way where you don't have to refer to any of the variables by name.
This should suffice. If you have more variables there is and easier way where you don't have to refer to any of the variables by name.
thanks Data_Null_
so there was no way the retain statement could retain those values by itself,w/o calling the coalesce f-ion?
In your program the values of GENDER and DOB are retained. BUT when the input statement is executed and the field is blank they are set to missing.
i am confused now.
I thought retain values never got set to missing.But lets consider the second observation where _gender is missing then gender gets set to missing too?
gender = coalesceC(_gender,gender);
Then how at the end gender gets the value if both the arguments are missing?
I was talking about GENDER and DOB in YOUR program. Even though they are RETAINED when the INPUT state executes the value of GENDER and DOB are replaced with what is read. On the second obs that is missing.
thank you.
And how can i fix the issue with the id=006 observations?
the gender and the date are missing in the first record with id=006 which means the second one should have missing fields too but that's not the case.I tried with if first.id and _gender= ' ' but was not successful
You will need to move the coalesce bit to another data step so you can use SET with BY ID.
Or to make in easier in some respect use the UPDATE statement this will fix the issue of DOB and GENDER being carried over from the previous ID. I does however carry forward ALL variables within each ID, which may not be what you want for all variables. You don't have any other missings but I've included the code to reset them as an example.
Message was edited by: data _null_
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.