DATA Step, Macro, Functions and more

Missing values in an array

Reply
Frequent Contributor
Posts: 138

Missing values in an array

 

Hi,

 

I have a dataset with ID, a date variable, a variable I created which has the month of the date variable but is always 2 digits (ie, 01, 02, etc.) and indicators over 24 months called mth_200501 through mth_200612. To sumthe number of months where mth_xxxxxx=1 prior to the date variable, I used the following code:

 

data want;

set have;

array mths{24} mth_200501--mth_200612;
  do i=1 to 24 until
  (vname(mth{i})=cats('mth', year(date1), date1_mth_char));
  prior_mths+mth{i};
  end; run;

 

It worked, but I received a message that there were 24 missing values generated by this code. There was only 1 person with a value of missing for date1, so my question is this: is the source of the 24 missing that the 1 person with missing values for date1 went through each month of the array?

 

Any help is much appreciated.

 

 

Super Contributor
Posts: 259

Betreff: Missing values in an array

The operator + causes the result to be missing if any operand is missing, using the sum-function helps.

Super User
Posts: 5,079

Re: Missing values in an array

It looks like you have 24 instances of DATE1=. and for each of those the function YEAR(DATE1) would generate a missing value.

 

The log should indicate where the missing values were generated (which line, at which point within the line), so the log should confirm whether this is the issue.

Trusted Advisor
Posts: 1,115

Re: Missing values in an array

As the UNTIL condition is not met because of the missing value of YEAR(DATE1), it is checked in each iteration of the DO loop, i.e. the full 24 times. Thus, 24 missing year values are generated from the single missing DATE1 value.

Ask a Question
Discussion stats
  • 3 replies
  • 191 views
  • 0 likes
  • 4 in conversation