BookmarkSubscribeRSS Feed
celbel
Calcite | Level 5

Hi, I want to use proc freq in order to create a table that shows me submissions created during a specific time period. 

The dates I have are listed as dd-mm-yyyy and I'm looking to calculate the year for the table to tell me how many submissions I have for the year, for example the time period runs from 2018-2021 so I want the table to tell me how many submissions I have for 2018, 2019, 2021 individually instead of it showing me every single submission on its own. 

Any idea on how to calculate the year?

 

5 REPLIES 5
Reeza
Super User
Is your date a SAS date, numeric with a dd-mm-yy format? Or is it a character variable?

If it's a SAS date, format the variable using YEAR4 in the PROC FREQ, proc means example below:
https://gist.github.com/statgeek/0cae5568752959b035516d6ac07a20fb
celbel
Calcite | Level 5

it is a character variable, in my table the dates show up as DDMMYYYY, for example, my received_date for the submissions show up as 10APR2018 18APR2018 24APR2018 and instead of each one showing up individually, I want to calculate the year for it just tell me that in 2018 I had __ number of submissions

PaigeMiller
Diamond | Level 26

Advice: always use numeric SAS date values, not character strings. There are so many SAS functions and formats and other features that work properly with numeric SAS date values, that will make your life easier, there's really no reason to not use them.


Example:

 

data intermediate;
    set have;
    date_numeric=input(date,date9.); /* Convert character date to numeric date */
run;
proc freq data=intermediate;
    tables date_numeric/out=want;
    format date_numeric year4.;
run;
--
Paige Miller
celbel
Calcite | Level 5

that worked, thank you!

Kurt_Bremser
Super User

Did you run PROC CONTENTS or inspect the variable attributes by right-clicking on it in the table viewer?

You say it is formatted as DDMMYYYY, but then you show dates in the SAS-typical DDMMMYYYY format.

Please confirm the type and display format of the variable before we proceed.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 705 views
  • 3 likes
  • 4 in conversation