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,
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;
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?
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;
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.