New Contributor
Posts: 3

# Horizontal sum across columns

Hi, I have a SAS dataset with three columns corresponding to YEAR, MONTH, and DAY. I want to create a new column that is the total length in days (i.e., DAY + 30*MONTH + 365*YEAR). How can I do this? Thanks!sum

Super User
Posts: 9,599

## Re: Horizontal sum across columns

I wouldn't use a calculation like that as you may miss leap years.  What is your duration here, you only provide one date, so what is the length in days *since*.

New Contributor
Posts: 3

## Re: Horizontal sum across columns

The data was given to me in YEARS, MONTHS, DAYS format, without regard to specific dates. So perhaps I will use 30.44 days/month and 365.25 days/year.

New Contributor
Posts: 3

## Re: Horizontal sum across columns

Another problem I am running into is that my data uses the values 97, 98, 99 to indicate things like "did not provide." For the purposes of this calculation, I want to set these all to zero. I tried using the DO OVER command, but I'm not sure why it's creating an empty data set.

Super User
Posts: 23,663

## Re: Horizontal sum across columns

Because you have a bug in your code, but we can't see your code so

Super User
Posts: 23,663

## Re: Horizontal sum across columns

If you have no additional information that's all you can do, but I'd guess as to there being more information somewhere....

Not applicable
Posts: 1

## Re: Horizontal sum across columns

I have the answer for you. But my SAS files are at home. I am at work now. I send you the SAS codes tonight. I have done the same thing for my datasets.

Not applicable
Posts: 1

## Re: Horizontal sum across columns

Assuming the dataset name is set1 and the formula you want to use is  ( DAY + 30*MONTH + 365*YEAR). Following code should work.

Proc sql;

Create table Set2 as

select

Set1.*,

SUM(DAY, (30*MONTH),(365*YEAR)) as TOTAL_DAYS

from

Set1.

;

quit;

Discussion stats
• 7 replies
• 1175 views
• 0 likes
• 5 in conversation