Appreciate if someone of you help me to write the 'case when ...' statement to derive the variable 'KHIREF' from the following data step?
data WORK.INSURANCE_POLICY_0002(drop=POLICY_NO checkdigit x_source_system_cd);
set WORK.INSURANCE_POLICY_0002;
format checkdigit z2.;
if POLICY_NO ^= '' then do;
/* combine source code and policy number */
khiref=substr(left(x_source_system_cd),2,1)!!substr(left(policy_no),1,2)!!substr(left(policy_no),4,7);
/* calculate the checkdigit modulo 97. replace 0 by 97 */
checkdigit=compress(mod(khiref,97));
if checkdigit=0 then checkdigit=97;
/* add the checkdigit */
khiref=substr(left(khiref),1,10)!!vvalue(checkdigit);
end;
run;
Sample data as follows:
data WORK.INSURANCE_POLICY_0002;
/*length POLICY_NO $20.;*/
POLICY_NO='94_0006288';
run;
Your data step needs fixing:
32 data WORK.INSURANCE_POLICY_0002(drop=POLICY_NO checkdigit x_source_system_cd); 33 set WORK.INSURANCE_POLICY_0002; 34 format checkdigit z2.; 35 if POLICY_NO ^= '' then do; 36 /* combine source code and policy number */ 37 khiref=substr(left(x_source_system_cd),2,1)!!substr(left(policy_no),1,2)!!substr(left(policy_no),4,7); 38 /* calculate the checkdigit modulo 97. replace 0 by 97 */ 39 checkdigit=compress(mod(khiref,97)); 40 if checkdigit=0 then checkdigit=97; 41 /* add the checkdigit */ 42 khiref=substr(left(khiref),1,10)!!vvalue(checkdigit); 43 end; 44 run; NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 37:20 39:21 NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). 39:12 39:25 NOTE: Variable x_source_system_cd is uninitialized.
Given the necessary intermediate steps, I'd recommend to stay with the data step, it's easier to read and maintain for such kind of logic.
See the blog post "The SELECT statement in the SAS DATA step."
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 25. 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.