BookmarkSubscribeRSS Feed
brophymj
Quartz | Level 8

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. 

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
brophymj
Quartz | Level 8

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 863 views
  • 0 likes
  • 2 in conversation