Help using Base SAS procedures

Formatting fields

Reply
Super Contributor
Posts: 259

Formatting fields

I am trying to change a date which is held in a string and of the format 01 DEC 2012 to a SAS date. Is this easy to do?

Also, I have a character field holding number which I would like to convert to number formats. i.e. 1,769 as a character field of length 10. 

Super User
Super User
Posts: 7,977

Re: Formatting fields

Yes, input reads text and converts to numeric (dates and times are actually numbers), put does the reverse so:

data want;

     set have;

     new_date=input(compress(string_date),date9.);  /* Compress as you have blanks */
     new_num=input(text_num,best.);
     format new_date date9.;   /* apply format, otherwise you will see number of days since a date in the past */
run;
Super Contributor
Posts: 259

Re: Formatting fields

Thanks rw9, that works for the dates. In the case of a the number it's not working. My number is currently a string of the form:

1,569

79

104

1,333

and so on. It's working for the numbers with commas but not the other ones.

Super User
Super User
Posts: 7,977

Re: Formatting fields

Ah, you need to use the comma format then:

  new_num=input(text_num,comma8.);

All formats can be found in the online help:

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

Ask a Question
Discussion stats
  • 3 replies
  • 209 views
  • 0 likes
  • 2 in conversation