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

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,

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18
proc print data=myhosprecords(where=(total_length_of_stay = -1)); run; 

use the where statement to select required observations. 

View solution in original post

6 REPLIES 6
Shmuel
Garnet | Level 18

Do it in one step:

data invalidlengthofstay validlengthofstay;
 set myhosprecords;
	if total_length_of_stay = -1 
	   then output invalidlengthofstay;
           else output validlengthofstay;
run;
ChrisNZ
Tourmaline | Level 20

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

 

 

Primavera
Quartz | Level 8

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,

 

Shmuel
Garnet | Level 18
proc print data=myhosprecords(where=(total_length_of_stay = -1)); run; 

use the where statement to select required observations. 

Primavera
Quartz | Level 8

Exactly what I was looking for. Thank you.

ScottBass
Rhodochrosite | Level 12

Could you please explain this a bit further?

 

Thanks,

 


 

http://support.sas.com/documentation/cdl/en/lestmtsref/63323/HTML/default/viewer.htm#n1xbr9r0s9veq0n...

 

You're welcome.

"Results Viewer" window

 

DMS or EG?  Both support a where clause.

 

 

 


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
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
  • 1426 views
  • 0 likes
  • 4 in conversation