BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

data have;

length Group $50;

input Group $ _NAME_ $ Value date $;

datalines;

 

wwww AARP 50 1jun2018

2fff BBRP 123 5may2015

;

run;

data have1;

set have;

date1 = input(date,anydtdte11.);

format date1 date9.;

run;

I am attempting to change the date format to read as a DDMMMYYYY format.  I tried several combinations including

format date1 ddmmmyyyy10.

4 REPLIES 4
Patrick
Opal | Level 21

What about:

format date1 ddmmyyn8.;

Reeza
Super User

In an INPUT statement you need an INFORMAT, which should reflect what the date looks like. 

 

This works for me. Please put your code in a code block in the future, it helps avoid issues when copy/pasting for testing.

 

data have;
length Group $50;
input Group $ _NAME_ $ Value date $; 
datalines;
wwww AARP 50 1jun2018
2fff BBRP 123 5may2015
;                   
run;

data have1;
set have;
date1 = input(date,date9.);
format date1 date9.;
run;
Cynthia_sas
Diamond | Level 26

Hi:

  Or, as an alternative, you could use an INFORMAT directly in the INPUT statement:

alt_informat.png

Either approach will work. I tend to use ANYDTDTE if I'm not certain that all the date values in the DATALINES appear the same.

Cynthia

Tom
Super User Tom
Super User

You didn't define a length for your character variable DATE. So SAS will default it to length $8, which will truncate values with two digit days and four digit years.   Not sure why you defined a length for one of your variables but not the other three. Best to define the lengths yourself and not force SAS to guess at what you want.

data have;
  length Group $50 _name_ $32 value 8 date $11;
  input Group _NAME_ Value date;
datalines;
wwww AARP 50 11jun2018
2fff BBRP 123 15-may-2015
;

Hopefully your real character variable is at least 9 characters long (or 11 if the date strings have punctuation around the month code).

data have1;
  set have;
  length date1 8;
  date1 = input(date,date11.);
  format date1 date9.;
run;
Obs    Group    _name_    value       date            date1

 1     wwww      AARP       50     11jun2018      11JUN2018
 2     2fff      BBRP      123     15-may-2015    15MAY2015

 

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
  • 1451 views
  • 2 likes
  • 5 in conversation