BookmarkSubscribeRSS Feed
Walternate
Obsidian | Level 7

 

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.

 

 

3 REPLIES 3
andreas_lds
Jade | Level 19

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

Astounding
PROC Star

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.

FreelanceReinh
Jade | Level 19

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 906 views
  • 0 likes
  • 4 in conversation