Hi, everybody, I have this dataset with 12 variables I am trying to calculate the CCI index for the variables. I am using this code but I am getting twice the variables without changing yes or no to its proper numeric value per condition. The code is the following. Also attached is the original csv file.
data risk;
set datasets.riskdata;
if diagnosis= 'TYPE1_DM' then diagnosis='y';
if diagnosis='TYPE2_DM' THEN DIAGNOSIS='n';
if diagnosis= 'PXECTMY' then diagnosis='n';
if los<0 then los=.;
array a{10} diagnosis dialysis lipiddis cbv_ds pvd neuropthy respprob cancrpre cbypass mi;
do i=1 to 10;
if A{i}=' ' then a{i}=.;
if a{i}= 999 then a{i}=.;
if a{i}= u then a{i}=.;
if a{i}= 9 then a{i}=.;
drop i;
end;
array b{10} diagnosis dialysis lipiddis cbv_ds pvd neuropthy respprob cancrpre cbypass mi;
array c{10} (2,3,2,1,1,1,1,3,1,2 );
do i=1 to 10;
if (B{i})='y' then CCI = CCI + B(c{i});
if (B{i})= 'n' then B(c{i})=0;
else if (B{i})='.' then CCI+B(c{i})=0;
drop i;
end;
run;and this is the error message
1. You cannot change types in place.
if A{i}=' ' then a{i}=.;
This indicates that a(i) is a list of character variables but then you try and set it to missing for numeric?
You need a new set of variables for type conversion with new names.
2. This is checking if the variable a(i) is equal to the variable u. I'm assuming you're actually looking for the text u, which means it needs to be in quotes.
if a{i}= u then a{i}=.;
3. You declare the same array twice. B and A are the same and you don't need to reference them twice.
array b{10} diagnosis dialysis lipiddis cbv_ds pvd neuropthy respprob cancrpre cbypass mi;
I've highlighted several of your issues. I suspect #1 is the biggest issue you're dealing with here.
@emma19901 wrote:
Hi, everybody, I have this dataset with 12 variables I am trying to calculate the CCI index for the variables. I am using this code but I am getting twice the variables without changing yes or no to its proper numeric value per condition. The code is the following. Also attached is the original csv file.
data risk; set datasets.riskdata; if diagnosis= 'TYPE1_DM' then diagnosis='y'; if diagnosis='TYPE2_DM' THEN DIAGNOSIS='n'; if diagnosis= 'PXECTMY' then diagnosis='n'; if los<0 then los=.; array a{10} diagnosis dialysis lipiddis cbv_ds pvd neuropthy respprob cancrpre cbypass mi; do i=1 to 10; if A{i}=' ' then a{i}=.; if a{i}= 999 then a{i}=.; if a{i}= u then a{i}=.; if a{i}= 9 then a{i}=.; drop i; end; array b{10} diagnosis dialysis lipiddis cbv_ds pvd neuropthy respprob cancrpre cbypass mi; array c{10} (2,3,2,1,1,1,1,3,1,2 ); do i=1 to 10; if (B{i})='y' then CCI = CCI + B(c{i}); if (B{i})= 'n' then B(c{i})=0; else if (B{i})='.' then CCI+B(c{i})=0; drop i; end; run;and this is the error message
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).81:18 82:19 83:17 84:17 91:21NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).82:4 84:4 90:32 92:29NOTE: Variable u is uninitialized.NOTE: Invalid numeric data, 'y' , at line 82 column 4.NOTE: Invalid numeric data, 'y' , at line 84 column 4.NOTE: Invalid numeric data, 'Y' , at line 82 column 4.NOTE: Invalid numeric data, 'Y' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'Y' , at line 82 column 4.NOTE: Invalid numeric data, 'Y' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'Y' , at line 90 column 32.Case_ID=641 DIAGNOSIS=y LOS=13 Dialysis=Y LipidDis=N CbV_DS=N PVD=N Neuropthy=Y RespProb=N CancrPre=N CBYPASS=N MI=N i=11 u= c1=2c2=3 c3=2 c4=1 c5=1 c6=1 c7=1 c8=3 c9=1 c10=2 CCI=. _ERROR_=1 _N_=1NOTE: Invalid numeric data, 'y' , at line 82 column 4.NOTE: Invalid numeric data, 'y' , at line 84 column 4.NOTE: Invalid numeric data, 'Y' , at line 82 column 4.NOTE: Invalid numeric data, 'Y' , at line 84 column 4.NOTE: Invalid numeric data, 'Y' , at line 82 column 4.NOTE: Invalid numeric data, 'Y' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'Y' , at line 82 column 4.NOTE: Invalid numeric data, 'Y' , at line 84 column 4.NOTE: Invalid numeric data, 'Y' , at line 82 column 4.NOTE: Invalid numeric data, 'Y' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'Y' , at line 90 column 32.Case_ID=1173 DIAGNOSIS=y LOS=7 Dialysis=Y LipidDis=Y CbV_DS=N PVD=N Neuropthy=Y RespProb=Y CancrPre=N CBYPASS=N MI=N i=11 u= c1=2c2=3 c3=2 c4=1 c5=1 c6=1 c7=1 c8=3 c9=1 c10=2 CCI=. _ERROR_=1 _N_=2NOTE: Invalid numeric data, 'y' , at line 82 column 4.NOTE: Invalid numeric data, 'y' , at line 84 column 4.NOTE: Invalid numeric data, 'Y' , at line 82 column 4.NOTE: Invalid numeric data, 'Y' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'Y' , at line 82 column 4.NOTE: Invalid numeric data, 'Y' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'N' , at line 82 column 4.NOTE: Invalid numeric data, 'N' , at line 84 column 4.NOTE: Invalid numeric data, 'Y' , at line 90 column 32.Case_ID=1234 DIAGNOSIS=y LOS=8 Dialysis=Y LipidDis=N CbV_DS=N PVD=N Neuropthy=Y RespProb=N CancrPre=N CBYPASS=N MI=N i=11 u= c1=2c2=3 c3=2 c4=1 c5=1 c6=1 c7=1 c8=3 c9=1 c10=2 CCI=. _ERROR_=1 _N_=3
No idea what a CCI index is but I would guess the following code could be close:
data risk;
set datasets.riskdata;
if diagnosis= 'TYPE1_DM' then diagnosis='y';
if diagnosis='TYPE2_DM' THEN DIAGNOSIS='n';
if diagnosis= 'PXECTMY' then diagnosis='n';
if los<0 then los=.;
array A{10} diagnosis dialysis lipiddis cbv_ds pvd neuropthy respprob cancrpre cbypass mi;
do i=1 to 10;
A{i} = upcase(A{i});
if A{i} not in ("Y", "N") then call missing(A{i});
end;
array c{10} (2,3,2,1,1,1,1,3,1,2);
CCI = 0;
do i = 1 to 10;
if A{i} = 'Y' then CCI = CCI + c{i};
end;
drop i;
run;
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!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.