08-20-2014 10:31 AM
I'm mergeing on claims information to a larger file called exposure
merge exposure(in=a) claims;
There are about 20 numeric claims fields attaching on and some character fields. Where there are no claims info to attach on to a given row in the exposure, the claims field is blank, I want this to be 0 for numeric fields and N/A for character fields.
Is there a way to do this rather than going through every field like if field1 = . then field1 = 0....
08-20-2014 11:08 AM
One approach is arrays. Without variable names/types I can't be too specific.
In the datastep code add something like this:
array claims <list the names of the numeric claims fields here>;
if <condition to determine no claims info> then do _I_=1 to dim(claims); claims[_I_]=0; end;
you can do similar for the character variables.
The condition you need might be something like
if sum(of claims(*))=0 then ..
08-20-2014 11:31 AM
Here's my code but I'm not sure what to put inside <condition to determine no claims info>
I obviously know the condition - it's if the cell is . then populate it with 0.
array claims<total_incurred total_no total_outstanding>;
if < . > then do _I_ to dim(claims) ; claims[_I_] = 0; end;
I'm getting errors such as
"too many array subscripts specified..."
"Syntax error expecting one or more..."
08-20-2014 11:43 AM
Here's one piece of the puzzle. There's a standard way to determine whether there is a matching claims record or not. This should become part of your tool kit:
merge exposure (in=a) claims (in=b);
if b=0 then do; /* no claims record */
You also may have to think a little harder about the solution. Could there be a variable in the EXPOSURE data set that contains a blank? Would it be appropriate to set that variable to 0 (or to "N/A") when there is no claims data? That can happen if you are not careful with the coding.
08-20-2014 04:12 PM
Here is one solution
Prepare some data
length sexsmall $ 4;
set sashelp.class (obs=10);
rename age=agesmall weight=weightsmall height=heightsmall ;
merge sashelp.class (in=a) a (in=b);
array allnum sexsmall-numeric-weightsmall;
array allchar sexsmall-character-weightsmall;
if b=0 then do;
do over allnum; allnum=0; end;
do over allchar; allchar="N/A"; end;
Need further help from the community? Please ask a new question.