title: Pig Script Function Question
body: <p>As can be seen in the following Pig code, I am repeating a set of statements for Attr1 and Attr2. Is there a way to extract it out in a function? Code samples would really help.</p>
  
  <pre><code>Attr1ValidRecs = FILTER BaseRecs BY Attr1 IS NOT NULL;
  Attr1ValidRecs_all = GROUP Attr1ValidRecs ALL;
  Attr1Count = FOREACH Attr1ValidRecs_all GENERATE COUNT(Attr1ValidRecs);
  Attr1CountStr = FOREACH Attr1Count GENERATE CONCAT('Recs with Attr1 not null : ',(chararray)$0);
  
  Attr1BaseCross = CROSS BaseRecsCount,Attr1Count;
  Attr1BaseRatio = FOREACH Attr1BaseCross GENERATE CONCAT('Ratio of Not Null Attr1 to Total Base Recs: ',(chararray)((double)$1/(double)$0));
  
  Attr2ValidRecs = FILTER BaseRecs BY Attr2 IS NOT NULL;
  Attr2ValidRecs_all = GROUP Attr2ValidRecs ALL;
  Attr2Count = FOREACH Attr2ValidRecs_all GENERATE COUNT(Attr2ValidRecs);
  Attr2CountStr = FOREACH Attr2Count GENERATE CONCAT('Recs with Attr2 not null : ',(chararray)$0);
  
  Attr2BaseCross = CROSS BaseRecsCount,Attr2Count;
  Attr2BaseRatio = FOREACH Attr2BaseCross GENERATE CONCAT('Ratio of Not Null Attr2 to Total Base Recs:
  ',(chararray)((double)$1/(double)$0));
  </code></pre>