BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
shasank
Quartz | Level 8

Hi SAS Community,

 

I am trying to solve this issue with date formatting. I just want to make the Enddate variable in a date format. I tried anydtdte and worddate. But all those end up with an error that the format doesnot exist.

 

 

data abcd ;
set abc ;
Informat Enddate : anydtdte20.;
run;

 

 

Code Enddate

A4466December 31, 2016
A7011December 31, 2015
A7042December 31, 2014
A7043December 31, 2014
A9544December 31, 2016
A9545December 31, 2016
B9000December 31, 2016
C1204December 31, 2013
C1300December 31, 2014
C1879June 30, 2013

 

 

Any help much appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If you are working from an existing character variable, instead of a reading from a source text file, then you will want to use the INPUT() function instead of the INPUT statement.  You will need to create a new numeric variable to store the date as you cannot store it back into the character variable.

data abcd ;
  set abc ;
  datevar=input(Enddate,anydtdte20.);
  format datevar date9.;
run;

View solution in original post

3 REPLIES 3
andreas_lds
Jade | Level 19

You can't change the type of a variable, you have to use the correct informat when reading data.

data have;

input Code $5. @7 Enddate anydtdte20.;

format Enddate date9.;

datalines;
A4466	December 31, 2016
A7011	December 31, 2015
A7042	December 31, 2014
A7043	December 31, 2014
A9544	December 31, 2016
A9545	December 31, 2016
B9000	December 31, 2016
C1204	December 31, 2013
C1300	December 31, 2014
C1879	June 30, 2013
;
run;
shasank
Quartz | Level 8

Hello Andreas. This is the log i get when SAS is run. The End date is in $31 format if it helps for the soulution.

data abcd ;
118 set abc ;
119 input Code $5. @7 Enddate anydtdte20.;
-----------
48
ERROR 48-59: The informat $ANYDTDTE was not found or could not be loaded.

120 format Enddate date9.;
------

ERROR 48-59: The format $DATE was not found or could not be loaded.

121 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.ABCD may be incomplete. When this step was stopped there were 0
observations and 2 variables.
WARNING: Data set WORK.ABCD was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

Tom
Super User Tom
Super User

If you are working from an existing character variable, instead of a reading from a source text file, then you will want to use the INPUT() function instead of the INPUT statement.  You will need to create a new numeric variable to store the date as you cannot store it back into the character variable.

data abcd ;
  set abc ;
  datevar=input(Enddate,anydtdte20.);
  format datevar date9.;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 861 views
  • 1 like
  • 3 in conversation