BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mmea
Quartz | Level 8

Hi 

I have a lot of code but in this specific part where I make a calculation for y for a plot:

 

**plot for day 1;
data plot1;
   x = today();
   *y = &totalpopulation/(&group1+&group2); 
   y=1;
run;

As you can see i commented the line out for the calculation, as most of the time the calculation (&group1+&group2) will be "." (missing) because of no data in the group. The plot should then be 100%, hence the other y=1.

 

This is very manual work for me. Beacuse i need to check if the (&group1+&group2) will be missing then I should use the other y otherwise the plot will be empty- and I will like to know if there is a if statement you can do here? if (&group1+&group2)  is  "." then put y=1 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Do you want something like this:

 

data plot1;
   x = today();
   if not (missing(&group1) and missing(&group2)) then y = &totalpopulation/sum(&group1,&group2)); 
   else y=1;
run;

If that's not it, then I really don't understand the problem and I would ask you to discuss the problem (not the code) in more detail. DO NOT ANSWER BY DISCUSSING SAS CODE, ANSWER BY EXPLAINING THE PROBLEM.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Do you want something like this:

 

data plot1;
   x = today();
   if not (missing(&group1) and missing(&group2)) then y = &totalpopulation/sum(&group1,&group2)); 
   else y=1;
run;

If that's not it, then I really don't understand the problem and I would ask you to discuss the problem (not the code) in more detail. DO NOT ANSWER BY DISCUSSING SAS CODE, ANSWER BY EXPLAINING THE PROBLEM.

--
Paige Miller
tarheel13
Rhodochrosite | Level 12

Stop adding things like &group1 + &group2. You should use sum function instead because the sum function ignores missing values. You should just use a do block with the missing function to evaluate only among non-missing values of group 1 and group 2 like this: 

data plot1;
x=today( ) ;
if ^missing(&group1) and ^missing(&group2) then do;
y=&totalpopulation/sum(&group1,&group2);
end;
else do;
y=1;
end;
run;