Hi,
I have a date format something like YYYYMMDD this: 20200329
How can i convert this to DDMMYYYY : 29032020
I want the column to be in numeric format with DDMMYYn8. when i use this format i am getting Date format column with *** as values
@vnreddy wrote:
Variable is in Numeric format.
No format is attached to it, i want the output column as well to be in Numeric format.
In SAS a format is instructions for how to display the values. You are using the word FORMAT when you mean TYPE. SAS has two types of variables, fixed length strings and floating point numbers.
You want to convert a number to another number. You want to treat the original numbers as if they are in the form YY,YYM,MDD (so the tens and ones place are the day of the month) and treat the target numbers as if they are in the form DD,MMY,YYY (so the tens are ones place are the year within the century).
So use PUT + Z8. format to convert the original number to text. Then use INPUT() + YYMMDD. informat to convert that text into a date number. Then you can use PUT() + DDMMYYN format to convert that date into a string in the right style. Now you can use an INPUT() function with the normal numeric informat to convert that string into a number.
want = input(put(input(put(have,z8.),yymmdd8.),ddmmyyn8.),8.);
Simply use another format? ddmmyy10.?
data have;
date=input('20200301',yymmdd8.);
format date ddmmyyn8.;
run;
Maxim 3: Know Your Data.
Is the variable character or numeric?
Does it have a format attached to it?
Variable is in Numeric format.
No format is attached to it, i want the output column as well to be in Numeric format.
Then you can convert it "in place":
data want;
set have;
date = input(put(date,z8.),yymmdd8.);
format date ddmmyyn8.;
run;
@vnreddy wrote:
Variable is in Numeric format.
No format is attached to it, i want the output column as well to be in Numeric format.
Thank you for solution.
I does gave me right output, but my expected output format should be Numeric instead of Date format.
@vnreddy wrote:
Thank you for solution.
I does gave me right output, but my expected output format should be Numeric instead of Date format.
That would be one of the dumbest things you can do. Keep dates as SAS dates, and use the proper format when outputting, either to a report or for use in another system that expects a string with a certain date format.
@Kurt_Bremser i know, unfortunately there is a new date source which came in few days back.
Need to map this column with existing column, which is in Numeric format.
Existing column from old system which is in Numeric format was used in number of DI jobs.
Rather than changing the old column format, it would be a good idea to change the new column to an existing format for rest of DI jobs to work.
Keeping dates like that is, well, good manners prevent me from writing what comes to my mind. I mean that. Really.
Take the opportunity to clean this NOW. Any day this is allowed to exist is a day wasted.
You already have a load of jobs that need to be cleaned one day. Adding another to this is only a loan you take out on your future, and it WILL come back to bite you in your behind. IT WILL.
@DavePrinsloo wrote:
Just to expand to convert back to numeric:
data want;
set have;
date = input( input(put(date,z8.),yymmdd8.), best.);
format date 8.;
run;
I have a t-shirt from the schlockmercenary.com store. Its front reads:
"If it's stupid and it works, it's still stupid, and you're lucky."
That just came to my mind during this discussion. Storing dates as some kind of non-date deprives everybody involved from making use of all the features SAS has built to handle date values.
Insanity.
While the conversion is, as you posted, a very simple thing, IT MUST NOT BE DONE. Dates are dates are dates.
As just one example of why the "numeric that sort of imitates a date" is a poor idea create a graph with the numeric but not a date values as a horizontal axis. Either a series or scatter would likely be best that has daily values. Make sure that the "dates" involved cross a year boundary.
If the graph doesn't look odd then I want to see the data.
Hi,
I have a date value like 20200321 like column A below
I want the output column in this format 21032020 like column B below
A | B |
20200321 | 21032020 |
Source column was in Numeric format, and i want the target column as well to be in Numeric format.
Like this?
data test;
a = '21mar2020'd;
b = a;
format a yymmddn8. b ddmmyyn8.;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.