BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
archibald
Obsidian | Level 7

Hi all, I want to compute incarceration weight gain using only valid values.

Values of 999  and . are considered invalid and should not be considered .

see below data

ID

prejail_weight

postjail_weight

100

120

65

101

80

140

102

200

175

103

110

178

104

999

999

105

.

90

106

75

999

107

189

76

108

69

89

109

125

110

110

105

85

111

210

210

 

Some tranformations are required as well.

1-weight gain is to be coded 00 if weight gain  is less than -15 pounds.

2-weight gain is  to be coded 99 if  weight  gain is-15 pounds or more.

3- weight gain is to be coded 99 if weight gain is missing.

 

Any help would be appreciated.

Thanks,

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

If you're going to analyze this data, I don't recommend doing this. 

 

You'll end up having to filter out the 0 and 99 for all your analytical procs, but it's better to leave them as missing in my opinion.

SAS has several ways to identify missing values, so you may to consider using those instead.

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000992455.htm

 

 

@RW9 code seems correct, does it not do what you'd like?

 

Check for missing values, if there are any, don't calculate the weight_gain since you can't. 

Then code them to different missing values. 

I've used different variable names since it's easier to type out so make sure to replace the variables with yours as required.

 

if nmiss(post, pre) =0 then weight_gain = post - pre;

if 0 < weight_gain < 15 then weight_gain = .A;
else if weight_gain >  15 then weight_gain = .B;
run;

View solution in original post

6 REPLIES 6
Reeza
Super User

Which part are you having trouble with? You say incarceration weight gain, will that be post-pre?

 

Can you post the code you have so far? You mention changing values to 99, would those then be considered invalid?

archibald
Obsidian | Level 7
I am having some issues when it comes to code the difference(post-pre weight). the value 99 of (post-pre weight) should be considered missing.
See specifications below:

1-weight gain is to be coded 00 if weight gain is less than -15 pounds.
2-weight gain is to be coded 99 if weight gain is-15 pounds or more.
3- weight gain is to be coded 99 if weight gain is missing.
4- else weight gain =weight gain
Reeza
Super User

If you're going to analyze this data, I don't recommend doing this. 

 

You'll end up having to filter out the 0 and 99 for all your analytical procs, but it's better to leave them as missing in my opinion.

SAS has several ways to identify missing values, so you may to consider using those instead.

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000992455.htm

 

 

@RW9 code seems correct, does it not do what you'd like?

 

Check for missing values, if there are any, don't calculate the weight_gain since you can't. 

Then code them to different missing values. 

I've used different variable names since it's easier to type out so make sure to replace the variables with yours as required.

 

if nmiss(post, pre) =0 then weight_gain = post - pre;

if 0 < weight_gain < 15 then weight_gain = .A;
else if weight_gain >  15 then weight_gain = .B;
run;
archibald
Obsidian | Level 7
Thank you very much, Reeza
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Not sure what the problem is?  Is seems to be a simple case of set the code column to 99, and then if weight gain is less than 15 set it to 00:

data have;
  input id prejail_weight postjail_weight;
datalines;
100 120 65
101 80 140
102 200 175
103 110 178
104 999 999
105 . 90
;
run;

data want;
  set have;
  code="99";
  if (prejail_weight not in (.,999) and postjail_weight not in (.,999)) then do;
    if postjail_weight-prejail_weight < 15 then code="00";
  end;
run;
archibald
Obsidian | Level 7
the code does not work. the difference post weight and pre weight returns 2 frequencies 00 and 99for all the cases.
I need to have an output similar to the one below where difference between post weight and pre weight is coded 00 and 99 as needed , else the values stay unchanged.

weight_gain
60
00
68
924
99
20
00
99

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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