Hello to all,
I have a dataset with the variables concerning the blood count.
I have dichotomized the variables in 0.1.
how do I do if I have a sex-dependent variable?
wbc for women (sex = 0) its range is from 370 to 500 the values out of the range become 0 inside equal to 1, for males (sex = 1) their range goes from 410 to 540 values out of the range become o and inside 1.
should the output be 0 and 1 in a single variable?
I tried in the second part of the eg.
eg 1
data datasetdummy;
set WORK.PPP;
if Sesso='F' then
Sesso=0;
else
Sesso=1;
*nuova variabile binaria riguardante il sesso l'ho chiamata sesso (0=donna,1=uomo);
if Interno='SI' then
Interno=0;
else
Interno=1;
* interno (si=0,no=1);
if NEUT <=90 then
NEUT=0;
else if NEUT>=450 then
NEUT=0;
else
NEUT=1;
*se NEUT non si trova tra 90-450 è uguale a 0 altrimenti è uguale a 1;
if LYMPH <=100 then
LYMPH=0;
else if LYMPH>=300 then
LYMPH=0;
else
LYMPH=1;
*uguale al commento sopra per tutte le variabili MONO EO BASO;
if MONO <=0 then
MONO=0;
else if MONO >=100 then
MONO=0;
else
MONO=1;
if EO <=0 then
EO=0;
else if EO>=40 then
EO=0;
else
EO=1;
if BASO <=0 then
BASO=0;
else if BASO>=5 then
BASO=0;
else
BASO=1;
if PLT<=130 then
PLT=0;
else if PLT>=330 then
PLT=0;
else
PLT=1;
if MCV<=800 then
MCV=0;
else if MCV>=970 then
MCV=0;
else
MCV=1;
if MCH <=270 then
MCH=0;
else if MCH>=340 then
MCH=0;
else
MCH=1;
if MCHC<=330 then
MCHC=0;
else if MCHC>=364 then
MCHC=0;
else
MCHC=1;
if WBC<=2600 then
WBC=0;
else if WBC>=7800 then
WBC=0;
else
WBC=1;
run;
eg2
data dsd;
set datasetdummy;
if RBC.Sesso=0<=2600 then
RBC=0;
else if RBC.Sesso=0>=7800;
else
RBC.Sesso=0=1;
if RBC.Sesso=1<=2600 then
RBC=0;
else if RBC.Sesso=1>=7800;
else
RBC.Sesso=1=1;
run;
does anyone know how to implement it? I tried this way !!
@michshoot wrote:
Hello to all,
how do I do if I have a sex-dependent variable?
wbc for women (sex = 0) its range is from 370 to 500 the values out of the range become 0 inside equal to 1, for males (sex = 1) their range goes from 410 to 540 values out of the range become o and inside 1.
should the output be 0 and 1 in a single variable?I tried in the second part of the eg.
1. When recoding I generally place the values into a new variable so that errors of coding are easy to debug.
2. Often with ranges such as this I create custom formats as then I do not need to modify the data at all and most analysis procedures will use the formatted values as categories UNLESS I have an instance such as you have where the ranges differ by another characteristic such as gender or age.
You can use logic results to assign 0, 1 such as
if sex=0 then do; wbc = (370 le wbc le 500); end; else do; wbc = (410 le wbc le 540); end;
SAS will assign a value of 1 to "true"
Its really hard to read that code. First, use the code window - its the {i} above post are, to post code as this retains formatting. Second use some code formatting, i.e. not all mixed case, use indentations etc. Also, provide some test data, otherwise we are just guessing.
From what I can tell here you have variables like NEU, LYMPH etc. Can I ask why? It is pretty much standard now in clinical trials to use CDISC models for the data, including this lab data, so why is it not in LB or ADLB format?
There are of course numerous ways to approach this, formats for instance with an if to format for male or female. You could build it all as nestled ifs, e.g:
... if sex="Male" then do; neut=ifn(90 < neut < 450,0,1); ... end; else do; neut=... end; ...
Or you can go the route of creating normal ranges and merging these on. This would be the most normal approach to the problem and its what labs tend to do. They would have a standard dataset with Gender, Age, Lower, Upper Extended Lower, Extended Upper. This dataset is then merged onto the lab data by age and gender to get the normal ranges which are then used to calculate out of range flags.
Look at the CDISC SDTM guidelines, its all there and has been thought out by many in the industry for quite some time.
For formatting code like that, you should be chased through SASVille with a priestess ringing a bell and repeatedly shouting "Shame! Shame! Shame!" following you.
And you unnecessarily complicate your conditions; try this instead:
data datasetdummy;
set WORK.PPP;
if Sesso = 'F'
then Sesso = 0;
else Sesso = 1; * nuova variabile binaria riguardante il sesso l'ho chiamata sesso (0=donna,1=uomo);
if Interno = 'SI'
then Interno = 0;
else Interno = 1; * interno (si=0,no=1);
if NEUT <= 90 or NEUT >= 450
then NEUT = 0;
else NEUT = 1; * se NEUT non si trova tra 90-450 è uguale a 0 altrimenti è uguale a 1;
if LYMPH <= 100 or LYMPH >= 300
then LYMPH = 0;
else LYMPH = 1; * uguale al commento sopra per tutte le variabili MONO EO BASO;
if MONO < 0 or MONO >= 100
then MONO = 0;
else MONO = 1;
if EO < 0 or EO >= 40
then EO = 0;
else EO = 1;
if BASO < 0 BASO >= 5
then BASO = 0;
else BASO = 1;
if PLT <= 130 or PLT >= 330
then PLT = 0;
else PLT = 1;
if MCV <= 800 or MCV >= 970
then MCV = 0;
else MCV = 1;
if MCH <= 270 or MCH >= 340
then MCH = 0;
else MCH = 1;
if MCHC <= 330 or MCHC >= 364
then MCHC = 0;
else MCHC = 1;
if WBC <= 2600 or WBC >= 7800
then WBC = 0;
else WBC = 1;
run;
Edit: changed MONO, EO and BASO.
RBC.Sesso is not a valid SAS name for a variable. Look into the "Columns" section of the dataset properties window or into the output of proc contents to get the real name.
If that column really has that name because it was imported that way, use 'RBC.Sesso'n as the name in your code.
To find documentation, do a google search for "sas XXXX", where XXXX is the thing you want to know about (statement, procedure, error text, whatever). Works fine for me any time.
@michshoot wrote:
no, they are two different variables. sesso is the sex (0=f,1=male) I have to create a new RCB variable with the values I have stratified by sex.
wbc for women (sex = 0) its range is from 370 to 500 the values out of the range become 0 inside equal to 1, for males (sex = 1) their range goes from 410 to 540 values out of the range become o and inside 1.
should the output be 0 and 1 in a single variable?
So you will need to declare an array:
array rbc_sex {2} rbc_f rbc_m; /* or whatever your rbc for female/male are called */
if rbc_sex{sesso+1} <= 2600 or rbc_sex{sesso+1} >= 7800
then rbc = 0;
else rbc = 1;
Is that what you intend to do?
Could you give an example for datasetdummy, so we can see the real names of your variables?
There's only one RBC and one WBC variable, nothing that is sex-specific. I still have no clue what you try to do with the syntax
if RBC=Sesso=0<=370
as that condition would only be true if RBC and Sesso were both 0. And the last part of the condition doesn't make any sense at all, as zero is always smaller than 370.
@michshoot wrote:
Hello to all,
how do I do if I have a sex-dependent variable?
wbc for women (sex = 0) its range is from 370 to 500 the values out of the range become 0 inside equal to 1, for males (sex = 1) their range goes from 410 to 540 values out of the range become o and inside 1.
should the output be 0 and 1 in a single variable?I tried in the second part of the eg.
1. When recoding I generally place the values into a new variable so that errors of coding are easy to debug.
2. Often with ranges such as this I create custom formats as then I do not need to modify the data at all and most analysis procedures will use the formatted values as categories UNLESS I have an instance such as you have where the ranges differ by another characteristic such as gender or age.
You can use logic results to assign 0, 1 such as
if sex=0 then do; wbc = (370 le wbc le 500); end; else do; wbc = (410 le wbc le 540); end;
SAS will assign a value of 1 to "true"
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: