BookmarkSubscribeRSS Feed
ALee
Calcite | Level 5

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!

 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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
PGStats
Opal | Level 21

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1134 views
  • 0 likes
  • 3 in conversation