New User
Posts: 1

# How do I adding numbers between 0 and 10 in a data set

Hey. I am using SAS 9.4 and trying to add the numbers between to set values to a data set (column D). The goal is to have the data count down so that 11 Jan 17 would be day 6, 12 January 17 would be day 5 etc.

My current data set looks like this:

Animal     Date               TIME                 Avgbout               Daysb4challenge

1           11Jan17             AM                      12                                6

1           12Jan17             AM                       12

1           13Jan17            AM                        12

1           14Jan17            AM                         12

1           15Jan17            AM                         16

1           16Jan17            AM                         14                               1

2           11Jan17              AM                       13                                5

2          12Jan17            AM                           14

2           13Jan17            AM                           13

2           14Jan17           AM                             15

2           15Jan17            AM                           12

2           16Jan17           AM                             11                           0

We tried to use COUNT to count between the numbers to no avail. I imagine that we can use a PROC EXPAND, but I ave only used a lag and lead statement before. Any help would be greatly appreciated!

Posts: 3,061

## Re: How do I adding numbers between 0 and 10 in a data set

There's no way for us to know what you are doing wrong because you haven't shown us your code.

Nevertheless, the INTCK function will allow you to count the number of days between your date variable and any other date.

for example

`daysb4challenge=intck('day',date,'18jan17'd);`

counts the number of days between date and January 18, 2017.

--
Paige Miller
Posts: 5,541

## Re: How do I adding numbers between 0 and 10 in a data set

Try the so caled double DOW technique:

``````data have;
input Animal Date :date7. ampm \$ TIME;
datalines;
1   11Jan17   AM   12
1   12Jan17   AM   12
1   13Jan17   AM   12
1   14Jan17   AM   12
1   15Jan17   AM   16
1   16Jan17   AM   14
2   11Jan17   AM   13
2   12Jan17   AM   14
2   13Jan17   AM   13
2   14Jan17   AM   15
2   15Jan17   AM   12
2   16Jan17   AM   11
;

data want;
do until(last.animal);
set have; by animal;
lastDate = max(lastDate, date);
end;
do until(last.animal);
set have; by animal;
daysToChalenge = intck("day",date,lastDate);
output;
end;
drop lastdate;
run;

proc print noobs; run;
``````
PG
Discussion stats
• 2 replies
• 97 views
• 0 likes
• 3 in conversation