BookmarkSubscribeRSS Feed
rohitkrishna
Calcite | Level 5

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

 

4 REPLIES 4
rohitkrishna
Calcite | Level 5
sorry it's not lss279 its datalines
Astounding
PROC Star

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.

Tom
Super User Tom
Super User

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.

ballardw
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1452 views
  • 0 likes
  • 4 in conversation