Hi,
I am getting two different date formats from the database for single variable.
I want the output to be consistent with mmddyy10. format.
How to do it ?
data want;
set have;
x=length(scan(due_date10X. 1, '-'));
if x = 4 then due_date_want = input(due_date10X, yymmdd10.);
else due_date_want = input(due_date10X, mmddyy10.);
run;
First take the first part of the string using SCAn(). If it's a length of 4, that's the YYMMDD format. Otherwise use MMDDYY for the format.
@Abhinav26 wrote:
Hi,
I am getting two different date formats from the database for single variable.
I want the output to be consistent with mmddyy10. format.
How to do it ?
value should be June 4, 2019.
@Abhinav26 wrote:
and yes only these two formats i have
You already received defective data. How can you be sure you won't have further defects when the source has already proven itself to be unreliable?
Return to sender, and require consistent formatting of data.
data want;
set have;
x=length(scan(due_date10X. 1, '-'));
if x = 4 then due_date_want = input(due_date10X, yymmdd10.);
else due_date_want = input(due_date10X, mmddyy10.);
run;
First take the first part of the string using SCAn(). If it's a length of 4, that's the YYMMDD format. Otherwise use MMDDYY for the format.
@Abhinav26 wrote:
Hi,
I am getting two different date formats from the database for single variable.
I want the output to be consistent with mmddyy10. format.
How to do it ?
Thanks but i want new variable with values in mmddyy10. format for both rows and that too using proc SQL.
@Abhinav26 wrote:
Thanks but i want new variable with values in mmddyy10. format for both rows and that too using proc SQL.
That's what it does, did you try it? There's no way I can know you're using SQL... (EDIT: My bad, It was in your subject but not in the question. Should be an easy change though)
You can switch the IF/THEN statements to a CASE statement or use the Query builder to replicate the functions using the advanced computation features.
Give it a shot and if you can't figure it out, post your code.
It worked, Thanks
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!
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.