I have a numeric sex variable with values of 0 or 1 (0=female, 1=male). I want to convert this to character variable so I can add the aforementioned format in a proc format statement.
The below code does not make a new variable "sex_c", and you can see in the proc contents output, sex is still showing as numeric.
Here's my code:
Data datasets.redcap_pde1;
set datasets.redcap_pde0;
Sex_c=PUT(sex,8.);
Drop sex_c;
run;
Results:
Obs Sex
1 0
2 1
3 1
4 1
5 1
6 0
7 0
Proc contents:
Variables in Creation Order
# Variable Type Len Format Informat Label
6 Sex Num 8 15. Sex
This is frustrating. I've been messing with this for hours. I originally had what you suggested, except for the . = "missing" and it didn't work, hence why I thought I needed to change to character to see it. It doesn't make sense to me why adding the above line of code would all of a sudden make everything work? I didn't really care about labeling the missing data as such and figured it would just output a <period> if there wasn't a 0 or 1 in the column and I would therefore know that . = missing.
2025 SAS Hackathon: There is still time!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!