Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Reclassifying a decimal version of month

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 09-15-2021 03:38 PM
(594 views)

I am trying to create a month variable from days; I divided my days variable by 30.5. My data looks like this:

```
Days Month
1 0.0327
1 0.0327
1 0.0327
1 0.0327
1 0.0327
2 0.065
2 0.065
2 0.065
2 0.065
2 0.065
2 0.065
3 0.098
3 0.098
3 0.098
```

Is there an easier way to reclassify month other than 'if than else' statements? For example, I know I could do:

```
data temp;
set mydata;
if 0<=month<1 then month_new=1;
else if 1<=month<2 then month_new=2;
else if 2<=month<3 then month_new=3;
....
run;
```

But is there a more efficient way? For example, assuming there are thirteen months, I tried:

```
data temp;
retain month_new;
set mydata;
do i=1 to 13;
if i <= month < (i+1) then month_new=i;
end;
run;
```

This applied the last number in the do loop, 13, to all data values.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

If you are trying to bin your days into 30 day intervals (not really months since months do not have a constant number of days during a year or in case of Feb even across different years) just use some arithmetic.

`month=floor(days/30);`

If you want to count from 1 instead of 0 just add one.

2 REPLIES 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

In general, fractional months don't make a lot of sense. The better solution, if possible, is to handle months as SAS date variables and then use actual SAS date functions such as INTCK to determine number of months since a given date. Then all of this repetitive coding goes away. SAS has done the hard work in computing months so you don't have to.

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

If you are trying to bin your days into 30 day intervals (not really months since months do not have a constant number of days during a year or in case of Feb even across different years) just use some arithmetic.

`month=floor(days/30);`

If you want to count from 1 instead of 0 just add one.

**SAS Innovate 2025** is scheduled for May 6-9 in Orlando, FL. Sign up to be **first to learn** about the agenda and registration!

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.

Ready to level-up your skills? Choose your own adventure.