Jared Vineyard
Jared Vineyard

Reputation: 11

Looping through multiple string variables and cases to create a numeric variable SPSS

I have a dataset in SPSS with 311 different variables and 1304 cases. 99 of those variables have ICD9 and ICD 10 codes which are sometimes only numeric (i.e. 303) and sometimes string (i.e. H233). I have made all of the variables string.

What I need to do is have SPSS go through each case and each of the 99 variables and see if it finds any of the codes from a large list of the codes, i.e.:

("3180","3181","3182","330","33111","33119",
"3314","33189","3319","3320","3321","3330",
"3332","3334","3335","3337","3339","334",
"335","343","34501","34581","3590","3591",
"3592","3593","3361","3368","3379","3418",
"34290","343","3440","34481","3449","34511",
"3453","34541","34561","34571","34591","3481",
"3484","3491","43401","43491","359","740",
"741","742","7595","78003","9962","99663",
"V452","V5301","V5302")

If it finds any for my specified list of variables I need it to make the variable ccc_n = 1, otherwise ccc_n needs to equal 0. I tried COMPUTE ccc_n = 0. How can I accomplish this? I have tried do repeat, do if, loop and vector but I can't seem to make it work.

Upvotes: 1

Views: 676

Answers (1)

eli-k
eli-k

Reputation: 11350

Try this:

do repeat vr=vr1 to vr99.
  compute ccc_n=any(vr, "3180","3181","3182","330","33111","33119" ....).
end repeat.

You should of course replace vr1 to vr99 with your real variable names (if they are not consecutive in the file you need to name them each separately). In the any() function enter all of your codes separated by commas.

Upvotes: 1

Related Questions