Hi all,
Currently, I'M facing sas date format issue in my existing code kindly give the solution for the below code
{
data _null_;
infile lss279;
input @1 sdte $char10.;
datalines;
25.12.2017
;
dte2 = put(dte1,ddmmyy10.);
dte2 = substr(dte1,7,4)||substr(dte1,4,2)||substr(dte1,1,2);
run;
)
and here is the output: (2017.12.25)
and my requirement is 25.12.2017 but why I am getting that results I'm not able to understand
and the thing is I'm using ZOS 8.1 version (mainframe )
Thanks & regards
rohitkrishna
Any time you use DATALINES, it must come at the end of the DATA step. So these statements would need to be moved:
dte2 = put(dte1,ddmmyy10.);
dte2 = substr(dte1,7,4)||substr(dte1,4,2)||substr(dte1,1,2);
Whichever one you use, it would have to appear after the INPUT statement and before the DATALINES statement.
Is source value a date variable or a character variable? Do you want to create a date variable or a character variable?
data test;
input @1 charvar $10. @1 datevar ddmmyy10.;
charvar2 = put(datevar,ddmmyyp10.);
datevar2 = input(charvar,ddmmyy10.);
format datevar datevar2 ddmmyyp10.;
datalines;
25.12.2017
;
Obs charvar datevar charvar2 datevar2 1 25.12.2017 25.12.2017 25.12.2017 25.12.2017
PS Not sure why you are using d-m-y order for your dates (or why people use m-d-y order either). It is just asking for confusion. Use either DATE9 or YYMMDD10 so that you don't accidentally confuse 10th of December with November 12th.
Use the DDMMYYX format. The X allows you to specify a separator.
In this case I think you want to use DDMMYYP10. with a date value instead of messing with character values. Character values will not sort correctly.
data example; input sdte ddmmyy10.; format sdte ddmmyyp10.; datalines; 25.12.2017 ; proc print; run;
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.