BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

I need to work with a data set with a date field in chat format .

The format is  $ATE9  and the informat is same $ATE9

Fr exampe: the date value looks like this  2020-12-2

My question: What is the format $ATE9?

How can I convert it to SAS date??

5 REPLIES 5
PaigeMiller
Diamond | Level 26

The is no built-in format $ATE

 

It must be a custom format, or a format created and saved by someone else. Look in your program to see if that is the case.

 

You can also use this option to ignore the format and apply your own.

 

options nofmterr;
--
Paige Miller
Ronein
Meteorite | Level 14

Thanks:

So as I understand I need to write the following code and then the format is going out from the variable?

Will informat also go out?

(Remind that both format and informat are $ATE9 (As i understand it is user defined )

What is the way to return to  default status after the proc sql?

options nofmterr;
proc sql;
create table as want
select  date
from have
;
quit;
PaigeMiller
Diamond | Level 26

@Ronein wrote:

Thanks:

So as I understand I need to write the following code and then the format is going out from the variable?

Will informat also go out?

(Remind that both format and informat are $ATE9 (As i understand it is user defined )


Please give it a try and let us know what happens.

 


@Ronein wrote:

 

What is the way to return to  default status after the proc sql?

options nofmterr;
proc sql;
create table as want
select  date
from have
;
quit;

options fmterr;

 

By the way, informats are irrelevant to SQL.

 

--
Paige Miller
Tom
Super User Tom
Super User

It is much more important to check the TYPE (and the LENGTH for character variables) than any FORMAT or INFORMAT that might (or might not) be attached to it.

 

If looks like your variable is of type CHAR and should have a length of 10 (not 9) to be able to store date strings with four digit years and hyphens.

 

If you use SAS code you can remove the format attached to variable which will make it easier to see what actual data is stored in the field.

 

So if your current dataset is named HAVE and the variable in question is named DATE then this code will make a new dataset named WANT with the format removed from the variable.

data want;
  set have;
   format date ;
run;
ballardw
Super User

If you run this code and examine the resulting format for the variable X you may be able to deduce a likely cause.

data example;
   x='2021-12-2';
   format x date9.;
run;

proc contents data=example;
run;

For those not interested in actually running the code you can see the "format" that @Ronein has in his data. No custom format just the way SAS will report this particular incorrect attempt at assigning an existing format.


Alphabetic List of Variables and Attributes
# Variable Type Len Format
1 x Char 9 $ATE9.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 446 views
  • 1 like
  • 4 in conversation