Hey,
I have many dates like this: 01.01.2018:00:00:00’. Now I want to see just the years in a proc freq. How can I do this?
Thanx a lot!
Caro
Use the Dtyear. format like this
data have;
do datetime = 1 to 1e9 by 1e4;
x = 1;
output;
end;
format datetime datetime20.;
run;
proc freq data=have;
tables datetime;
format datetime dtyear.;
run;
This doesn't look like a date, but a datetime-value. Try
format dateVar dtYear4.;
in proc freq.
Use the Dtyear. format like this
data have;
do datetime = 1 to 1e9 by 1e4;
x = 1;
output;
end;
format datetime datetime20.;
run;
proc freq data=have;
tables datetime;
format datetime dtyear.;
run;
Just assign the DTYEAR4. format to your date variable, and PROC FREQ will automatically group by years:
data have;
input datetime :e8601dt19.;
format datetime nldatms19.;
datalines;
2018-01-01T00:00:00
2018-01-01T00:00:00
2019-01-01T00:00:00
;
proc freq data=have;
format datetime dtyear4.;
tables datetime;
run;
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 save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.