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.
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.
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;
Post your log please.
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;
What about good, old RTM?
SAS-Docs are at https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=pgmsashome&docsetTarget=h...
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.