BookmarkSubscribeRSS Feed
kwhood
Fluorite | Level 6

I have a categorical variable that has either 1) missing "." data or a category for 2) "CAH" or 3) "children's".  I need to redesignation the Missing or blank observation should really have been coded as "adult" for an adult care hospital.

 

when I ran a frequency it told me how many hospitals I had in CAHs or Children's hospitals;  

output.PNG    

 

So I tried to recode the variable with the following statement:

 

if type="." then type="adult";
else if type="CAH" then type="CAH";
else if type="Children's" then type="Children";
run;


proc freq data=weighting;
tables type;
run;

 

I received the same output as posted above.  I also tried to having the missing outside if quotes (see below)

 

if type=. then type="adult";
else if type="CAH" then type="CAH";
else if type="Children's" then type="Children";
run;

 

When I did this I got this result:

Capture.PNG

 

So all the 3 catergories became recoded as "adult" hospitals.  I don't know what I am doing wrong.  Can someone help me fix the program so that the missing data become adult hospitals and the other existing categories stay the same??

 

Thank you!!!!

K

4 REPLIES 4
ballardw
Super User

Missing is a bit different for character and numeric. the . is for numeric.

 

Try

 

if missing(type) then type='Adult';

or

if missing='' then type='Adult';  /* that is two single quotes with no space between*/

 

stat_sas
Ammonite | Level 13

Hi,

 

Instead of recoding type in output, try to recode type in orginal data set weighting then run proc freq to get the desired results.

 

 

Tom
Super User Tom
Super User

One of those two data steps should have given messages about needing to convert between numeric and character data.

If TYPE is numeric then you can use TYPE=. to test for missing.

But if TYPE is character then you need to use TYPE=' ' to test for missing.

You can also use MISSING(TYPE) to test for missing.

kwhood
Fluorite | Level 6
Super! Thanks so much. I didn't know that at all.

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
  • 4 replies
  • 2255 views
  • 0 likes
  • 4 in conversation