- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 08-12-2020 04:33 AM
(2445 views)
Hi,
I have a data set with the following format in date column: 28feb2018:00:00:00.000. How do I write a code to count all the observations with the year 2018, 2019 etc.?
Any help would be much appreciated.
Thanks a lot.
10 REPLIES 10
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Is the variable numeric and a format attached displaying it as datetime, or is it an alphanumeric variable?
If you already have a sas-dateime variable, try:
proc summary data=have nway;
class datetime_var;
format datetime_var dtyear4.;
output out=counted(drop=_type_ rename=(_freq_=count));
run;
Code is untested.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Do something like this
data have;
do dt = '01jan2018 00:00:00'dt to '31dec2020 00:00:00'dt by 3600;
output;
end;
format dt datetime20.;
run;
proc freq data=have;
table dt;
format dt dtyear.;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am getting an error with the do statement
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Post your log please.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please try the below code , please check the count dataset from proc freq
data have;
input datetime:anydtdtm.;
format datetime datetime20.;
cards;
28feb2018:00:00:00.000
;
data want;
set have;
year=year(datepart(datetime));
run;
proc freq data=want;
table year / out=count;
run;
Thanks,
Jag
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What does have signify?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
have is the input dataset, since you did not provide the sample dataset, i created a sample dataset names as have and then used in subsequently
Thanks,
Jag
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
also, what does cards signify?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What about good, old RTM?
SAS-Docs are at https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=pgmsashome&docsetTarget=h...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
In order to put the data using the input statement we can use either cards or datalines , indicating that after these statements the data portion starts
Thanks,
Jag
Jag