Hello everyone, I am new to programming in sas and in a table I have an alphanumeric column called "day" that contains values in text format: 07/20/2022 and I want to convert it to 20220720 (yyyymmdd).
How could I change the values of this table?
Thank you very much in advance, I would also appreciate any type of documentation where I can read about this
You do NOT want to store dates in character variables in SAS. Convert the character strings to numeric date values, and apply a suitable format:
data _null_;
chardate = "07/20/2022";
numdate = input(chardate,mmddyy10.);
format numdate yymmddn8.;
put numdate=;
run;
There are actually three topics you would have to study: the PUT function, the INPUT function, and how SAS handles dates. With that knowledge, it only take one statement (within a DATA step):
day = put(input(day, mmddyy10.), yymmddn8.);
:
data have; date="07/20/2022"; run; data want; set have; format date2 YYMMDDN8.; date2 = input(date, mmddyy10.); run;
hello, you can find a lot of similar topics in the forum.
Why would you want a character "date"?
They don't work well as graph axis.
You have to go through a similar two-step every time you want to display a date in a different form for any purpose.
You will have to add variables to the data set to create any sort of report group such as monthly, quarterly or annually that can be accomplished with report or analysis procedure simply by changing the format in procedures like Proc Report, Tabulate, Means, Summary , Univariate and the list goes on.
Then there is the bit about dealing with anything that wants to use the difference between dates.
For almost any use leave it as the SAS date value and apply formats as desired.
Here's a great, but longer and in depth, reference for dates and times in SAS
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/...
You do NOT want to store dates in character variables in SAS. Convert the character strings to numeric date values, and apply a suitable format:
data _null_;
chardate = "07/20/2022";
numdate = input(chardate,mmddyy10.);
format numdate yymmddn8.;
put numdate=;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.