Hi guys,
suppose to have the following:
data DB;
input ID :$20. Admission :date09. Discharge :date09. Index Age_class;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 1 6
0001 21FEB2015 31DEC2015 0 6
0001 01MAR2018 30SEP2018 0 7
0001 01JAN2019 31DEC2019 0 7
0002 01JAN2015 31DEC2015 1 3
0002 01JAN2019 31OCT2019 0 5
0003 08FEB2014 10MAR2014 1 3
0003 16JUN2015 13JUL2015 0 3
0004 04MAY2016 10MAY2016 1 8
0004 13SEP2017 15NOV2017 0 8
0004 09DEC2018 31DEC2018 0 8
;
Age_class takes values from 1 to 8.
Is there a way to get the following?
data DB;
input ID :$20. Admission :date09. Discharge :date09. Index Age_class Age_class1 Age_class2 Age_class3 .... Age_class7 Age_class8;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 1 6 1 1 1 ... 1 1
0001 21FEB2015 31DEC2015 0 6 0 0 0 ... 0 0
0001 01MAR2018 30SEP2018 0 7 0 0 0 ... 0 0
0001 01JAN2019 31DEC2019 0 7 0 0 0 ... 0 0
0002 01JAN2015 31DEC2015 1 3 1 1 0 ... 1 1
0002 01JAN2019 31OCT2019 0 5 0 0 0 ... 0 0
0003 08FEB2014 10MAR2014 1 3 1 1 0 ... 1 1
0003 16JUN2015 13JUL2015 0 3 0 0 0 ... 0 0
0004 04MAY2016 10MAY2016 1 8 1 1 1 ... 1 0
0004 13SEP2017 15NOV2017 0 8 0 0 0 ... 0 0
0004 09DEC2018 31DEC2018 0 8 0 0 0 ... 0 0
;
In other words I need to fill Age_class* variables (Age_class1, Age_class2, ..., Age_class8) with 1 if at Index = 1 the patient IS NOT in that age_class and 0 otherwise.
Note that Index = 1 is always the first date (Admission-Discharge) for each patient and there is always one Index = 1 for each patient.
For example: pts 0001 at Index = 1 has Age_class = 6. Age_class1, Age_class2, Age_class3, Age_class4, Age_class5, Age_class7, Age_class8 will be filled with 1 because the patient is not contributing to that age_class while it will be 0 at Age_class6 because it is contributing.
Note also, that there are other dates that will be put to 0 because of no interest.
I know, I can do "if then else" but it will take a lot of coding to perform all comparisons.
Thank you very much for your help.
Try this
data want(drop = i);
set DB;
array a {8} Age_class1 - Age_class8;
do i = 1 to dim(a);
a[i] = Index = 1;
if Index = 1 then a[Age_class] = 0;
end;
run;
Try this
data want(drop = i);
set DB;
array a {8} Age_class1 - Age_class8;
do i = 1 to dim(a);
a[i] = Index = 1;
if Index = 1 then a[Age_class] = 0;
end;
run;
Maybe I'm not understanding this properly, because the admission dates and discharge dates are not used anywhere. Also maybe I'm not understanding the general problem of creating these zero and 1 variables, why do you need these if you have the value of INDEX? Seems redundant to me, what is the next step after you have these 0 and 1 variables, what will you do with them, what analysis or plot or table are you going to create?
@NewUsrStat wrote:
Thank you very much for your comment. Yes it is true that there's the variable Age_class but I need to count every time every ID is not contributing to an age class from 1 to 8 except the one to which it belongs. Yes, dates will not be used but are there and I left them to show that Index = 1 at first date.
Far too vague of an explanation about what you will do next with this data.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.