- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 11-19-2018 07:38 AM
(2898 views)
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;
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have to implement this logic in DI studio and I was asked to use only
'case when'
'case when'
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
See the blog post "The SELECT statement in the SAS DATA step."