BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Abelp9
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

5 REPLIES 5
Astounding
PROC Star

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.);

:

 

kelxxx
Quartz | Level 8
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.

ballardw
Super User

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.

Kurt_Bremser
Super User

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 3675 views
  • 5 likes
  • 6 in conversation