Hi all,
I am taking data from a survey that is numerical. The questions is how many days in a month have you had good mental health days. In the code book 0 days= 88 but 1 day is just 1 and so on. I need to change the 88 to 0 without messing up other numbers of days like 10, 20, 30 (ultimately need to look at the avg and the 88 is messing this obviously). My current code does not do that- my dataset puts in a (*) when it is 10,20,30. Here is what I have so far. Thanks so much!
proc format;
run;
You could do something as below.
data have;
do menthlth=-1, 0, 1, 10, 30, 31, 32, 88;
output;
end;
stop;
run;
proc format;
invalue menthlth
low-<0= .
31<-high=.
other=_same_
;
run;
data want;
set have;
menthlth_recoded=input(menthlth, menthlth.) ;
run;
proc print data=want;
run;
If you want to use the value for CALCULATIONS, such as mean number of good health days then you want to have a value of 0. Which means a format is not going to help. Formats are only related to Displaying values.
Options: Recode the value(s) you don't want for calculation into either the same variable (caution applies) or into a new variable.
Another is if the data is read from a text file to use an INFORMAT that does that mapping when the value is first read. Which might look like:
Proc format; invalue read88to0_ 88=0 99=.R 77=.D other=[2.] ; run; /* in a data step to read the file*/ Informat menthlth read88to0_.
Note the informat I propose will read values of 77 and 99 to special missing so you can follow that the original question had a response like 'Don't Know' or 'Refused' if those are the meanings for 77 and 99 (from similar survey data).
This way you can tell why specific values are missing and use them if needed by testing for the .D or .R missing value, such as possibly imputing only some of the values.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.