BookmarkSubscribeRSS Feed
Ranjeeta
Pyrite | Level 9

data O1617_wide;
set O1617_sorted;
by cihi_key;
retain var_cost fix_cost new_idc totalcost;
if first.cihi_key then call missing(var_cost, fix_Cost, new_idc, totalcost);
var_cost = sum(VDC_LABOUR,VDC_SUPPLY_GENE,VDC_SUPPLY_SPEC,VDC_OTHER);
fix_Cost=sum(FDC_LABOUR,FDC_OTHER,FDC_EQU);
new_idc = sum(IVC, IFC);
totalcost=sum(DC,IDC);
if last.cihi_key then output;
drop VDC_LABOUR VDC_SUPPLY_GENE VDC_SUPPLY_SPEC VDC_OTHER FDC_LABOUR FDC_OTHER FDC_EQU IVC IFC;
run;

 

Hello 

Can someone advise what would call missing do in the above code and which records will be output?

7 REPLIES 7
singhsahab
Lapis Lazuli | Level 10

Hi Ranjeeta,

 

Call Missing routine assign an ordinary numeric value . (dot) to each numeric variable in the argument list. 

 

In your case whenever if condition is true for first group variable, call routine assign . (dot) value for all listed variable. later when the next group variable will come it will again assign the same .

 

if first.cihi_key then call missing(var_cost, fix_Cost, new_idc, totalcost);

 

Thanks...

SASKiwi
PROC Star

This statement:

if last.cihi_key then output;

Means only one row for each value of cihi_key will be output and it will be the last row if there are multiple rows with the same value.

 

Astounding
PROC Star

This program was likely written by someone who didn't know what they were doing.

 

CALL MISSING could be removed.  The variables that it impacts are all replaced by the next four lines in the program.  Those variables would have the same values even if CALL MISSING was not part of the program.

 

The program outputs only one observation per CIHI_KEY ... the very last one.  However, it does NOT add up anything across observations.  If a CIHI_KEY has 10 observations, the first nine are totally ignored and have no impact on the final result.

 

In order to clean up the programming logic, you need to thoroughly understand what the program is supposed to accomplish.

Shmuel
Garnet | Level 18

@Astounding, pay attention that call missing relates to retained variables

in order to sum input variables which are droped at output

retain var_cost fix_cost new_idc totalcost;
if first.cihi_key then call missing(var_cost, fix_Cost, new_idc, totalcost);

sum() function ignores missing values.

 

it seems to me that @singhsahab answer is the right and relevant one.

Astounding
PROC Star

So far, there is no real answer.  CALL MISSING works on retained variables, but that doesn't really matter.  Those variables get replaced right after CALL MISSING executes ... every time.

 

There is no attempt to sum up anything across observations ... at all.

 

There is no reason to compute the retained variables, if they are going to be replaced, and the observation then deleted most of the time.

 

We are missing any sort of explanation as to what the program is trying to accomplish.  So yes, there is an answer as to what CALL MISSING does.  But there are bigger questions about how to fix a nonworking program.

Ranjeeta
Pyrite | Level 9
In the above program the variable var_cost is missing from the sum functon
Shmuel
Garnet | Level 18

@Astounding was right. To fix the code try:

data O1617_wide;
  set O1617_sorted;
by cihi_key;
    retain var_cost fix_cost new_idc totalcost;

   if first.cihi_key then call missing(var_cost, fix_Cost, new_idc, totalcost);

var_cost = sum(var_cost, VDC_LABOUR, VDC_SUPPLY_GENE, VDC_SUPPLY_SPEC, VDC_OTHER);

fix_Cost=sum(fix_Cost, FDC_LABOUR, FDC_OTHER, FDC_EQU);

new_idc = sum(new_idc, IVC, IFC);

totalcost=sum(totalcost, DC, IDC);

if last.cihi_key then output;

drop VDC_LABOUR VDC_SUPPLY_GENE VDC_SUPPLY_SPEC VDC_OTHER FDC_LABOUR FDC_OTHER FDC_EQU IVC IFC;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1852 views
  • 5 likes
  • 5 in conversation