Hi, I am trying to extract only the months from these dates in a new column labelled as "Month" in PROC SQL.
Could someone please help me?
it is in "2020-03-21" format..
month(dateVariable) as monthNum --> do I replace "dateVariable" with my column name?
@rliu0712 wrote:
it is in "2020-03-21" format..
SAS has variable types and formats.
Types can be numeric or character and formats control how a variable is displayed. Your answer doesn't answer the question asked - is your variable numeric or character. Either can appear as you've shown but how they're stored can differ.
data demo;
dateCharacter = "2020-03-21";
date_numeric = "21Mar2020"d;
format date_numeric yymmddd10.;
run;
title 'Can you tell the difference between numeric and character dates?';
proc print data=demo;
run;
@rliu0712 wrote:
month(dateVariable) as monthNum --> do I replace "dateVariable" with my column name?
Yes, replace it with your variable name.
Yes, I just figured out it is numeric with format YYMMDD10.
the "select month(dateVariable) as monthNum from table" does not seem to work..
Depending on what you are doing if you have an actual date value you may not need a new variable. SAS formatted values are honored by reporting and most graphing and analysis procedures. Possibly just using the YEAR4. format in the step you want to use the data will work.
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.