I have been working on the code below to obtain cases for cath, cabg, pci, hyper, obes, diab as well as conduct frequencies and chi-square analysis. However, I have not been successful in keeping the cagb, pci, hyper, obes, and diab variables after running the arrays. Based on my code and the log, can anyone please tell me why these new variables are not showing up to run the frequencies, etc.? I am trying to set these variables up for a logistical regression model.
/*create library using mydata and the folder*/
libname mydata"/home/wwhitner0/Cardio";
data new; set mydata.mdahos;
if age_yrs <= 35 then Agegroup=1;
else if age_yrs <=44 then Agegroup=2;
else if age_yrs <=54 then Agegroup=3;
else if age_yrs <=64 then agegroup=4;
else if age_yrs <=74 then agegroup=4;
else if age_yrs >=75 then agegroup=5;
if race=1 then _race=1;
else if race=2 then _race=2;
if payer1=01 then payer=1;
else if payer1=02 then payer=2;
else if payer1=04 then payer=4;
else if payer1=05 then payer=5;
else if payer1=08 then payer=8;
else if payer1=12 then payer=12;
run;
proc freq; tables agegroup payer _race;
run;
data new; set mydata.mdahos;
cath=0;
array _CATH (15) proc_1-proc_15;
do i=1 to 15;
if _CATH (i) >=3721 and _cath (i) <=3723
then CATH=1;
if _Cath(i) >=8850 and _cath(i)<=8858
then cath=1;
end;
drop i;
run;
proc freq data=new;
tables cath;
run;
data new; set mydata.mdahos;
CABG=0;
array _CABG (15) proc_1-proc_15;
do i=1 to 15;
if _CABG (i) >=3610 and _CABG (i) <=3620
then CABG=1;
end;
drop i;
run;
proc freq data =new;
tables cabg;
run;
data new; set mydata.mdahos;
PCI=0;
array _PCI (15) proc_1-proc_15;
do i=1 to 15;
if _PCI (i) >=3600 and _PCI (i) <=3606
then PCI=1;
end;
drop i;
run;
proc freq data=new;
tables pci;
run;
data new; set mydata.mdahos;
hyper=0;
array _hyper (15) diag1-diag15;
do i=1 to 15;
if _hyper (i) >=4019 and _hyper (i) <=40291
then hyper=1;
if _hyper(i) >=4050 and _hyper(i)<=40599
then hyper=1;
end;
drop i;
run;
proc freq data=new;
tables hyper;
run;
data new; set mydata.mdahos;
Obes=0;
array _obes (15) diag1-diag15;
do i=1 to 15;
if _obes (i) >=2780 and _obes (i) <=27802
then obes=1;
end;
drop i;
run;
proc freq data=new;
tables obes;
run;
data new; set mydata.mdahos;
diab=0;
array _diab (15) diag1-diag15;
do i=1 to 15;
if _diab (i) >=25000 and _diab (i) <=25002
then diab=1;
if _diab(i) >=25010 and _diab(i)<=25012
then PCI=1;
end;
drop i;
run;
proc freq data=new;
tables diab;
run;
proc freq data=new;
proc freq; tables agegroup _race payer;
proc freq; tables payer* _race;
proc freq; tables cath * payer * _race;
proc freq; tables cabg * payer * _race;
proc freq; tables PCI * payer * _race;
proc freq; tables obes*cath;
proc freq; tables obes*cabg;
proc freq; tables obes*pci;
proc freq; tables hyper*cath;
proc freq; tables hyper*cabg;
proc freq; tables hyper*pci;
proc freq; tables diab*cath;
proc freq; tables diab*cabg;
proc freq; tables diab*pci;
proc freq; tables payer* _race / chisq relrisk cl;
proc freq; tables cath * payer * _race / chisq relrisk cl;
proc freq; tables cabg * payer * _race / chisq relrisk cl;
proc freq; tables PCI * payer * _race / chisq relrisk cl;
proc freq; tables obes*cath / chisq relrisk cl;
proc freq; tables obes*cabg / chisq relrisk cl;
proc freq; tables obes*pci / chisq relrisk cl;
proc freq; tables hyper*cath / chisq relrisk cl;
proc freq; tables hyper*cabg / chisq relrisk cl;
proc freq; tables hyper*pci / chisq relrisk cl;
proc freq; tables diab*cath / chisq relrisk cl;
proc freq; tables diab*cabg / chisq relrisk cl;
proc freq; tables diab*pci / chisq relrisk cl;
proc freq; tables agegroup*obes/chisq relrisk cl;
proc freq; tables agegroup*hyper/chisq relrisk cl;
proc freq; tables agegroup*diab/chisq relrisk cl;
proc freq; tables obes*_race/chisq relrisk cl;
proc freq; tables hyper*_race/chisq relrisk cl;
proc freq; tables diab*_race/chisq relrisk cl;
run;
@wwhitner0 Please post the solution and mark it as solved for future users. If you cannot - just mark it as solved with your comment.
Thank you. Unfortunately, it is not working.
code:
/*create library using mydata and the folder*/
libname mydata"/home/wwhitner0/Cardio";
data new; set mydata.mdahos;
if age_yrs <= 35 then Agegroup=1;
else if age_yrs <=44 then Agegroup=2;
else if age_yrs <=54 then Agegroup=3;
else if age_yrs <=64 then agegroup=4;
else if age_yrs <=74 then agegroup=4;
else if age_yrs >=75 then agegroup=5;
if race=1 then _race=1;
else if race=2 then _race=2;
if payer1=01 then payer=1;
else if payer1=02 then payer=2;
else if payer1=04 then payer=4;
else if payer1=05 then payer=5;
else if payer1=08 then payer=8;
else if payer1=12 then payer=12;
run;
proc freq data=new;
proc freq; tables agegroup payer _race;
run;
data new; set mydata.mdahos;
cath=0;
array _CATH (15) proc_1-proc_15;
do i=1 to 15;
if _CATH (i) >=3721 and _cath (i) <=3723
then CATH=1;
if _Cath(i) >=8850 and _cath(i)<=8858
then cath=1;
end;
drop i;
run;
proc freq data=new;
tables cath;
run;
data new; set mydata.mdahos;
CABG=0;
array _CABG (15) proc_1-proc_15;
do i=1 to 15;
if _CABG (i) >=3610 and _CABG (i) <=3620
then CABG=1;
end;
drop i;
run;
proc freq data =new;
tables cabg;
run;
data new; set mydata.mdahos;
PCI=0;
array _PCI (15) proc_1-proc_15;
do i=1 to 15;
if _PCI (i) >=3600 and _PCI (i) <=3606
then PCI=1;
end;
drop i;
run;
proc freq data=new;
tables pci;
run;
data new; set mydata.mdahos;
hyper=0;
array _hyper (15) diag1-diag15;
do i=1 to 15;
if _hyper (i) >=4019 and _hyper (i) <=40291
then hyper=1;
if _hyper(i) >=4050 and _hyper(i)<=40599
then hyper=1;
end;
drop i;
run;
proc freq data=new;
tables hyper;
run;
data new; set mydata.mdahos;
Obes=0;
array _obes (15) diag1-diag15;
do i=1 to 15;
if _obes (i) >=2780 and _obes (i) <=27802
then obes=1;
end;
drop i;
run;
proc freq data=new;
tables obes;
run;
data new; set mydata.mdahos;
diab=0;
array _diab (15) diag1-diag15;
do i=1 to 15;
if _diab (i) >=25000 and _diab (i) <=25002
then diab=1;
if _diab(i) >=25010 and _diab(i)<=25012
then PCI=1;
end;
drop i;
run;
proc freq data=new;
tables diab;
run;
proc freq data=new;
proc freq; tables agegroup _race payer;
proc freq; tables payer* _race;
proc freq; tables cath * payer * _race;
proc freq; tables cabg * payer * _race;
proc freq; tables PCI * payer * _race;
proc freq; tables obes*cath;
proc freq; tables obes*cabg;
proc freq; tables obes*pci;
proc freq; tables hyper*cath;
proc freq; tables hyper*cabg;
proc freq; tables hyper*pci;
proc freq; tables diab*cath;
proc freq; tables diab*cabg;
proc freq; tables diab*pci;
proc freq; tables payer* _race / chisq relrisk cl;
proc freq; tables cath * payer * _race / chisq relrisk cl;
proc freq; tables cabg * payer * _race / chisq relrisk cl;
proc freq; tables PCI * payer * _race / chisq relrisk cl;
proc freq; tables obes*cath / chisq relrisk cl;
proc freq; tables obes*cabg / chisq relrisk cl;
proc freq; tables obes*pci / chisq relrisk cl;
proc freq; tables hyper*cath / chisq relrisk cl;
proc freq; tables hyper*cabg / chisq relrisk cl;
proc freq; tables hyper*pci / chisq relrisk cl;
proc freq; tables diab*cath / chisq relrisk cl;
proc freq; tables diab*cabg / chisq relrisk cl;
proc freq; tables diab*pci / chisq relrisk cl;
proc freq; tables agegroup*obes/chisq relrisk cl;
proc freq; tables agegroup*hyper/chisq relrisk cl;
proc freq; tables agegroup*diab/chisq relrisk cl;
proc freq; tables obes*_race/chisq relrisk cl;
proc freq; tables hyper*_race/chisq relrisk cl;
proc freq; tables diab*_race/chisq relrisk cl;
run;
/*proc logistic data=new
plots (only)=(effect);
class sex;
model cath (event='1')= sex;
title1 'Logistic Regression Model';
run;
title;*/
data new;
set mydata.mdahos; <- uses data set to start off iwth;
if age_yrs <= 35 then Agegroup=1;
else if age_yrs <=44 then Agegroup=2;
else if age_yrs <=54 then Agegroup=3;
else if age_yrs <=64 then agegroup=4;
else if age_yrs <=74 then agegroup=4;
else if age_yrs >=75 then agegroup=5;
if race=1 then _race=1;
else if race=2 then _race=2;
if payer1=01 then payer=1;
else if payer1=02 then payer=2;
else if payer1=04 then payer=4;
else if payer1=05 then payer=5;
else if payer1=08 then payer=8;
else if payer1=12 then payer=12;
run;
data new; set mydata.mdahos; <- erases previous NEW data set AND all variables created;
I don't think you made the changes. See my comments above.
As an aside to your question about arrays; you can reduce the Proc Freq code to something like:
Proc freq data=new; tables agegroup _race payer payer* _race; tables (obes hyper diab)*(cath cabg pci _race) / chisq relrisk cl ; tables payer* _race / chisq relrisk cl; tables (cath cabg pci) * payer * _race / chisq relrisk cl; tables agegroup*(obes hyper diab)/chisq relrisk cl; run;
You may have a large number of requests on a single tables statement as long as you want the same options for each.
Syntax like (a b c) *(x y z) creates tables of the combinations: a*x a*y a*z b*x b*y b*z c*x c*y c*z. So you can shorten the table requests. Multiple Proc Freq calls might cause SAS to reload the data multiple times where multiple tables statements within a single call will require the data load only once.
Also calling the same tables request without and with an option like chisq or relrisk creates duplicate output of the basic table.
Hi Ballardw,
My colleague found the issue. Everything is working well now.
Thanks,
Wendy
@wwhitner0 Please post the solution and mark it as solved for future users. If you cannot - just mark it as solved with your comment.
The solution we used and works is as follows:
*create library using mydata and the folder*/
libname mydata"/home/wwhitner0/Cardio";
data new; set mydata.mdahos;
if age_yrs <= 35 then Agegroup=1;
else if age_yrs <=44 then Agegroup=2;
else if age_yrs <=54 then Agegroup=3;
else if age_yrs <=64 then agegroup=4;
else if age_yrs <=74 then agegroup=4;
else if age_yrs >=75 then agegroup=5;
if race=1 then _race=1;
else if race=2 then _race=2;
if payer1=01 then payer=1;
else if payer1=02 then payer=2;
else if payer1=04 then payer=4;
else if payer1=05 then payer=5;
else if payer1=08 then payer=8;
else if payer1=12 then payer=12;
cath=0;
array _CATH (15) proc_1-proc_15;
do i=1 to 15;
if _CATH (i) >=3721 and _cath (i) <=3723
then CATH=1;
if _Cath(i) >=8850 and _cath(i)<=8858
then cath=1;
end;
drop i;
CABG=0;
array _CABG (15) proc_1-proc_15;
do i=1 to 15;
if _CABG (i) >=3610 and _CABG (i) <=3620
then CABG=1;
end;
drop i;
PCI=0;
array _PCI (15) proc_1-proc_15;
do i=1 to 15;
if _PCI (i) >=3600 and _PCI (i) <=3606
then PCI=1;
end;
drop i;
hyper=0;
array _hyper (15) diag1-diag15;
do i=1 to 15;
if _hyper (i) >=4019 and _hyper (i) <=40291
then hyper=1;
if _hyper(i) >=4050 and _hyper(i)<=40599
then hyper=1;
end;
drop i;
diab=0;
array _diab (15) diag1-diag15;
do i=1 to 15;
if _diab (i) >=25000 and _diab (i) <=25002
then diab=1;
if _diab(i) >=25010 and _diab(i)<=25012
then PCI=1;
end;
drop i;
Obes=0;
array _obes (15) diag1-diag15;
do i=1 to 15;
if _obes (i) >=2780 and _obes (i) <=27802
then obes=1;
end;
drop i;
run;
proc freq data =new;
tables cath cabg pci obes hyper diab;
run;
proc freq data=new; tables agegroup _race payer
payer* _race
cath * payer * _race
cabg * payer * _race
PCI * payer * _race
obes*cath
obes*cabg
obes*pci
hyper*cath
hyper*cabg
hyper*pci
diab*cath
diab*pci
diab*cabg
payer* _race
cath * payer * _race
cabg * payer * _race
PCI * payer * _race
obes*cath
obes*cabg
obes*pci
hyper*cath
hyper*cabg
hyper*pci
diab*cath
diab*cabg
diab*pci
agegroup*obes
agegroup*hyper
agegroup*diab
obes*_race
hyper*_race
diab*_race /chisq relrisk cl;
run;
/*create library using mydata and the folder*/
libname mydata"/home/wwhitner0/Cardio";
data new; set mydata.mdahos;
if age_yrs <= 35 then Agegroup=1;
else if age_yrs <=44 then Agegroup=2;
else if age_yrs <=54 then Agegroup=3;
else if age_yrs <=64 then agegroup=4;
else if age_yrs <=74 then agegroup=4;
else if age_yrs >=75 then agegroup=5;
if race=1 then _race=1;
else if race=2 then _race=2;
if payer1=01 then payer=1;
else if payer1=02 then payer=2;
else if payer1=04 then payer=4;
else if payer1=05 then payer=5;
else if payer1=08 then payer=8;
else if payer1=12 then payer=12;
cath=0;
array _CATH (15) proc_1-proc_15;
do i=1 to 15;
if _CATH (i) >=3721 and _cath (i) <=3723
then CATH=1;
if _Cath(i) >=8850 and _cath(i)<=8858
then cath=1;
end;
drop i;
CABG=0;
array _CABG (15) proc_1-proc_15;
do i=1 to 15;
if _CABG (i) >=3610 and _CABG (i) <=3620
then CABG=1;
end;
drop i;
PCI=0;
array _PCI (15) proc_1-proc_15;
do i=1 to 15;
if _PCI (i) >=3600 and _PCI (i) <=3606
then PCI=1;
end;
drop i;
hyper=0;
array _hyper (15) diag1-diag15;
do i=1 to 15;
if _hyper (i) >=4019 and _hyper (i) <=40291
then hyper=1;
if _hyper(i) >=4050 and _hyper(i)<=40599
then hyper=1;
end;
drop i;
diab=0;
array _diab (15) diag1-diag15;
do i=1 to 15;
if _diab (i) >=25000 and _diab (i) <=25002
then diab=1;
if _diab(i) >=25010 and _diab(i)<=25012
then PCI=1;
end;
drop i;
Obes=0;
array _obes (15) diag1-diag15;
do i=1 to 15;
if _obes (i) >=2780 and _obes (i) <=27802
then obes=1;
end;
drop i;
run;
proc freq data =new;
tables cath cabg pci obes hyper diab;
run;
proc freq data=new; tables agegroup _race payer
payer* _race
cath * payer * _race
cabg * payer * _race
PCI * payer * _race
obes*cath
obes*cabg
obes*pci
hyper*cath
hyper*cabg
hyper*pci
diab*cath
diab*pci
diab*cabg
payer* _race
cath * payer * _race
cabg * payer * _race
PCI * payer * _race
obes*cath
obes*cabg
obes*pci
hyper*cath
hyper*cabg
hyper*pci
diab*cath
diab*cabg
diab*pci
agegroup*obes
agegroup*hyper
agegroup*diab
obes*_race
hyper*_race
diab*_race /chisq relrisk cl;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.