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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.