Learning SAS? Welcome to the exclusive online community for all SAS learners.

Missing data

Reply
Occasional Contributor
Posts: 13

Missing data

I am running a program and one of the first things I do in the code is create blocks based on the month and year of the sample.  For example, if the data were collected in June of 2014 I create a time block:

 

IF YEAR=2014 AND MONTH=6 THEN BLOCK='JUN14';

 

There are 37 blocks in my code but when I run my program, it only gives me results for 26 of them.  It gets the first 25 correctly, skips the next 11 and gets the final one.

 

What could be causing this?  Thanks in advance for any assistance.

Super User
Posts: 17,912

Re: Missing data

Show more of your code. Are you sure you have 37 blocks? Is there a reason you're not using SAS dates, but a character variable?

 

block = mdy(year, month, 1);
format block monyy7.;
Occasional Contributor
Posts: 13

Re: Missing data

Code below:

 

****** DEFINE TIME BLOCKS ****;

IF YEAR=2012 AND MONTH=12 THEN BLOCK='DEC12';
IF YEAR=2013 AND MONTH=1 THEN BLOCK='JAN13';
IF YEAR=2013 AND MONTH=2 THEN BLOCK='FEB13';
IF YEAR=2013 AND MONTH=3 THEN BLOCK='MAR13';
IF YEAR=2013 AND MONTH=4 THEN BLOCK='APR13';
IF YEAR=2013 AND MONTH=5 THEN BLOCK='MAY13';
IF YEAR=2013 AND MONTH=6 THEN BLOCK='JUN13';
IF YEAR=2013 AND MONTH=7 THEN BLOCK='JUL13';
IF YEAR=2013 AND MONTH=8 THEN BLOCK='AUG13';
IF YEAR=2013 AND MONTH=9 THEN BLOCK='SEP13';
IF YEAR=2013 AND MONTH=10 THEN BLOCK='OCT13';
IF YEAR=2013 AND MONTH=11 THEN BLOCK='NOV13';
IF YEAR=2013 AND MONTH=12 THEN BLOCK='DEC13';
IF YEAR=2014 AND MONTH=1 THEN BLOCK='JAN14';
IF YEAR=2014 AND MONTH=2 THEN BLOCK='FEB14';
IF YEAR=2014 AND MONTH=3 THEN BLOCK='MAR14';
IF YEAR=2014 AND MONTH=4 THEN BLOCK='APR14';
IF YEAR=2014 AND MONTH=5 THEN BLOCK='MAY14';
IF YEAR=2014 AND MONTH=6 THEN BLOCK='JUN14';
IF YEAR=2014 AND MONTH=7 THEN BLOCK='JUL14';
IF YEAR=2014 AND MONTH=8 THEN BLOCK='AUG14';
IF YEAR=2014 AND MONTH=9 THEN BLOCK='SEP14';
IF YEAR=2014 AND MONTH=10 THEN BLOCK='OCT14';
IF YEAR=2014 AND MONTH=11 THEN BLOCK='NOV14';
IF YEAR=2014 AND MONTH=12 THEN BLOCK='DEC14';
IF YEAR=2015 AND MONTH=1 THEN BLOCK='JAN15';
IF YEAR=2015 AND MONTH=2 THEN BLOCK='FEB15';
IF YEAR=2015 AND MONTH=3 THEN BLOCK='MAR15';
IF YEAR=2015 AND MONTH=4 THEN BLOCK='APR15';
IF YEAR=2015 AND MONTH=5 THEN BLOCK='MAY15';
IF YEAR=2015 AND MONTH=6 THEN BLOCK='JUN15';
IF YEAR=2015 AND MONTH=7 THEN BLOCK='JUL15';
IF YEAR=2015 AND MONTH=8 THEN BLOCK='AUG15';
IF YEAR=2015 AND MONTH=9 THEN BLOCK='SEP15';
IF YEAR=2015 AND MONTH=10 THEN BLOCK='OCT15';
IF YEAR=2015 AND MONTH=11 THEN BLOCK='NOV15';
IF YEAR=2015 AND MONTH-12 THEN BLOCK='DEC15';

Thanks for the help.
Super User
Posts: 6,971

Re: Missing data


vicdicenzo wrote:

Code below:

 

****** DEFINE TIME BLOCKS ****;

IF YEAR=2012 AND MONTH=12 THEN BLOCK='DEC12';
IF YEAR=2013 AND MONTH=1 THEN BLOCK='JAN13';
IF YEAR=2013 AND MONTH=2 THEN BLOCK='FEB13';
IF YEAR=2013 AND MONTH=3 THEN BLOCK='MAR13';
IF YEAR=2013 AND MONTH=4 THEN BLOCK='APR13';
IF YEAR=2013 AND MONTH=5 THEN BLOCK='MAY13';
IF YEAR=2013 AND MONTH=6 THEN BLOCK='JUN13';
IF YEAR=2013 AND MONTH=7 THEN BLOCK='JUL13';
IF YEAR=2013 AND MONTH=8 THEN BLOCK='AUG13';
IF YEAR=2013 AND MONTH=9 THEN BLOCK='SEP13';
IF YEAR=2013 AND MONTH=10 THEN BLOCK='OCT13';
IF YEAR=2013 AND MONTH=11 THEN BLOCK='NOV13';
IF YEAR=2013 AND MONTH=12 THEN BLOCK='DEC13';
IF YEAR=2014 AND MONTH=1 THEN BLOCK='JAN14';
IF YEAR=2014 AND MONTH=2 THEN BLOCK='FEB14';
IF YEAR=2014 AND MONTH=3 THEN BLOCK='MAR14';
IF YEAR=2014 AND MONTH=4 THEN BLOCK='APR14';
IF YEAR=2014 AND MONTH=5 THEN BLOCK='MAY14';
IF YEAR=2014 AND MONTH=6 THEN BLOCK='JUN14';
IF YEAR=2014 AND MONTH=7 THEN BLOCK='JUL14';
IF YEAR=2014 AND MONTH=8 THEN BLOCK='AUG14';
IF YEAR=2014 AND MONTH=9 THEN BLOCK='SEP14';
IF YEAR=2014 AND MONTH=10 THEN BLOCK='OCT14';
IF YEAR=2014 AND MONTH=11 THEN BLOCK='NOV14';
IF YEAR=2014 AND MONTH=12 THEN BLOCK='DEC14';
IF YEAR=2015 AND MONTH=1 THEN BLOCK='JAN15';
IF YEAR=2015 AND MONTH=2 THEN BLOCK='FEB15';
IF YEAR=2015 AND MONTH=3 THEN BLOCK='MAR15';
IF YEAR=2015 AND MONTH=4 THEN BLOCK='APR15';
IF YEAR=2015 AND MONTH=5 THEN BLOCK='MAY15';
IF YEAR=2015 AND MONTH=6 THEN BLOCK='JUN15';
IF YEAR=2015 AND MONTH=7 THEN BLOCK='JUL15';
IF YEAR=2015 AND MONTH=8 THEN BLOCK='AUG15';
IF YEAR=2015 AND MONTH=9 THEN BLOCK='SEP15';
IF YEAR=2015 AND MONTH=10 THEN BLOCK='OCT15';
IF YEAR=2015 AND MONTH=11 THEN BLOCK='NOV15';
IF YEAR=2015 AND MONTH-12 THEN BLOCK='DEC15';

Thanks for the help.

Such code is an utter eyesore and must not be permitted to exist. Kill it three days before yesterday.

Even if you insist on the very inefficient (I was tempted to write stupid) "MMMYY" notation, which prevents you from using standard sorting techniques, such assignments can and MUST be handled with the simple use of functions and formats in three lines:

_tempdate = put(mdy(month,1,year),date9.);
block = substr(_tempdate,3,3) !! substr(tempdate,8,2);
drop _tempdate;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 6,971

Re: Missing data

And stop writing code in all-uppercase. We're long past the 1950's.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 10,541

Re: Missing data

One of the first things I do with a problem like that is proc freq:

 

Proc freq data=have;

   table year*month/list missing;

run;

The missing will show if you have either varaible missing in combination with the other. The List shows them one line at a time which is easier to read for potentially largish cross list of values.

 

Also look for things like year = 2014 and month=66 (or 16) or any other value for year or month you did not expect. Since your variables appear to be numeric the sort order of the output would make it easy to see and the count of rows will tell if there actually are 37 combinations of values actually present in the data.

Occasional Contributor
Posts: 13

Re: Missing data

I ran the proc freq as you suggested and it shows that all bocks are there. Yet when I ran the program, the same 11 blocks are absent from the analysis.

Super User
Posts: 17,912

Re: Missing data

With what you've provided we can't say much. Can you post a proc contents of the source data, the proc freq output and the code that generates the missing values. Do all of those have missing information in some other field you need for your analysis? Most likely that's the issue. 

Super User
Posts: 6,971

Re: Missing data

To assist in correct order, I would always set such values in yyyymm format, so in your example I'd get the character value "201406".

But the best method would be to use aligned SAS dates with a proper format:

length block 5; /* sufficient precision for SAS dates */
format block yymmn6.;
block = input(put(year,z4.)!!put(month,z2.)!!'01',yymmdd8.);

That way you keep the option to apply SAS date math and functions.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 8 replies
  • 425 views
  • 0 likes
  • 4 in conversation