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...
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.