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!
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.
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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.