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;
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:
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
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*/
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.
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.
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.
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.