'How can i count the difference between dates within the same column (SAS)
Total beginner stuff in SAS, but still..How can i count the number of dates within the same column for each ID?
Dataset want (I have added the variable Count_date, which i want to create):
ID datechar Count_date
1 01-09-2014 1
1 01-09-2014 1
1 01-09-2014 1
1 02-09-2014 2
1 02-09-2014 2
1 02-09-2014 2
1 03-09-2014 3
1 03-09-2014 3
1 03-09-2014 3
2 01-08-2014 1
2 01-08-2014 1
2 01-08-2014 1
2 01-08-2014 1
2 02-08-2014 2
2 02-08-2014 2
2 02-08-2014 2
2 02-08-2014 2
2 04-08-2014 4
2 04-08-2014 4
2 04-08-2014 4
2 04-08-2014 4
3 05-06-2011 1
3 05-06-2011 1
3 05-06-2011 1
3 05-06-2011 1
3 08-06-2011 4
3 08-06-2011 4
3 08-06-2011 4
3 08-06-2011 4
I want to create there variable Count_date. I have tried:
Data want;
set have;
by ID;
retain count_date;
if first.datechar then count_date = 1;
else count_date = count_date + 1;
run;
What am i doing wrong?
Thanks alot!!
Solution 1:[1]
BY and FIRST are not specified correctly.
Data want;
set have;
by ID datechar;
retain count_date;
if first.ID then count_date = 1;
else if first.datechar then count_date + 1;
run;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Reeza |
