BookmarkSubscribeRSS Feed
almay2121
Calcite | Level 5

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;

value menthlth
88= 0
 
;
run;
 
 
data sasfile.Final_subset2;
set sasfile.Final_subset;
format  menthlth menthlth. ; /*apply formats to created variables*/

run;

3 REPLIES 3
Patrick
Opal | Level 21

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;
Astounding
PROC Star
Why complicate things with formats?

if mentlhlth = 88 then mentlhlth = 0;
ballardw
Super User

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.

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 401 views
  • 1 like
  • 4 in conversation