Hi there,
I am fairly new to SAS and I am using SAS 9.4.
I am working with a data set (hospital inpatient records) that has about one hundred thousand records and about forty variables. Each patient has their unique study ID. Some of the variables are birth-date, admission-date, separation-date, 15 variables for ICD codes of diagnoses of each patient, dead or alive flag, etc. One of the variables is total_length_of_stay and documents for the datasheet say "invalid data will be recorded as -1". My question is how can I see which study IDs have -1 in their total_length_of_stay. Right now the only way I can do this is with use of a flag:
data myhosprecords;
set myhosprecords;
if total_length_of_stay = -1 then invalidlength=1;
else invalidlength=0;
run;
data invalidlengthofstay validlengthofstay;
set myhosprecords;
if invalidlength=1 then output invalidlengthofstay;
else output validlengthofstay;
run;
Is there a simpler way without creating a flag and two other datasheets to find those individuals whose total_length_of_stay = -1?
Thanks,
proc print data=myhosprecords(where=(total_length_of_stay = -1)); run;
use the where statement to select required observations.
Do it in one step:
data invalidlengthofstay validlengthofstay;
set myhosprecords;
if total_length_of_stay = -1
then output invalidlengthofstay;
else output validlengthofstay;
run;
>how can I see which study IDs have -1
How do you want to "see"? Creating a table seems the best way.
data BAD;
set MYHOSPRECORDS;
where TOTAL_LENGTH_OF_STAY = -1 ;
run;
Even better you don't need to create table, you can directly run a report using any procedure, by just adding the same WHERE clause.
Thank you very much. Your suggestion is very neat and efficient.
By seeing I meant seeing the result in the "Results Viewer" window without needing to create the new file "BAD". I looked into proc print but that did not seem like what I wanted.
>Even better you don't need to create table, you can directly run a report using any procedure, by just adding the same WHERE clause.
Could you please explain this a bit further?
Thanks,
proc print data=myhosprecords(where=(total_length_of_stay = -1)); run;
use the where statement to select required observations.
Exactly what I was looking for. Thank you.
Could you please explain this a bit further?
Thanks,
You're welcome.
"Results Viewer" window
DMS or EG? Both support a where clause.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.