DATA Step, Macro, Functions and more

Format problem

Reply
Occasional Contributor
Posts: 9

Format problem

Ho can I convert  2017-09-28 (Numeric, E8601da. format) into a character 8601 format.

 

It seems I just cant ever get the hang on formats and informats. Somebody please help.

Contributor
Posts: 30

Re: Format problem

data want;
format new_date1 yymmdd10.;
date='2017-09-28';
new_date1=input(date,yymmdd10.); /* SAS numberic date format- better approach */
new_date=put(input(date,yymmdd10.),mmddyy10.); /* character format */
run;

Is this what you are looking for? Your question is not clear.

 

Super User
Posts: 13,292

Re: Format problem

It may help to show what you did and why you weren't satisfied with the result.

A common issue is people trying to change an existing variable from numeric to character. SAS doesn't do that.

Occasional Contributor
Posts: 9

Re: Format problem

Yes. That is true. Whenever, I use put or input I "compress" the variable
in the bracket. That converts the variable into character and character
cannot be converted using a numeric format. My mistake, lesson learnt.
Super User
Super User
Posts: 7,931

Re: Format problem

[ Edited ]

Should be easy.  So you have something like this where your existing variable is an actual date.

data have ;
  date='28SEP2017'd;
  format date e8601da. ;
  put date= comma7. +1 date e8601da. +1 date date9.;
run;

Log

date=21,090  2017-09-28 28SEP2017

And you want to create a new variable that has a string in it that looks like a date.

data want ;
  set have;
  string = put(date,e8601da.);
run;

 

Ask a Question
Discussion stats
  • 4 replies
  • 119 views
  • 0 likes
  • 4 in conversation