BookmarkSubscribeRSS Feed
gowtham112
Obsidian | Level 7

Hi,

 

I have a column Named  "Date" which is in format YYYY-MM  and they are stored in character value .

I want to convert them into numeric format so that I can create a new variable called "Newdate" to store SAS date value.

 

Thanks in Advance.

4 REPLIES 4
Kurt_Bremser
Super User

You have to make a decision which day to use for an incomplete date.

If that should be the first of the month, do

newdate = input(date !! '-01',yymmdd10.);
format newdate yymmddd10.;
gowtham112
Obsidian | Level 7

Hi  KurtBremser,

 

Thank you very much for your  response!!!  it worked perfectly I really appreciate your help 

 

Again, thanks so much!!

 

Best,

Gowtham

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Dates are stored as number of days since a given time.  So to convert your text into a number SAS needs to be able to calculate how many days since that date there are, and without day value it cannot do this, hence it cannot convert to numeric date.  The same thing happens with times, so seconds since.  Give it a default number, then you can always apply a format - i.e. change the display of the underlying data - to YYYY-MM.

gowtham112
Obsidian | Level 7
Hi RW9,

This is great!!!
Thank you so much!!!
I really appreciate your help

Again, thanks so much!!

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!

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
  • 4 replies
  • 952 views
  • 1 like
  • 3 in conversation