BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Caro17
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

3 REPLIES 3
andreas_lds
Jade | Level 19

This doesn't look like a date, but a datetime-value. Try

format dateVar dtYear4.;

in proc freq.

PeterClemmensen
Tourmaline | Level 20

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;
Kurt_Bremser
Super User

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;
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1266 views
  • 0 likes
  • 4 in conversation