turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Learn SAS
- /
- Analytics U
- /
- Missing data

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-28-2017 04:51 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to vicdicenzo

07-28-2017 04:56 PM

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.;
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

07-31-2017 01:55 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to vicdicenzo

08-01-2017 02:13 AM

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

Maxims of Maximally Efficient SAS Programmers

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to vicdicenzo

08-01-2017 02:14 AM

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

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to vicdicenzo

07-28-2017 06:21 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ballardw

07-31-2017 01:54 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to vicdicenzo

07-31-2017 03:53 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to vicdicenzo

07-29-2017 05:24 AM

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

Maxims of Maximally Efficient SAS Programmers