BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
maroulator
Obsidian | Level 7

I have the data in the attached .csv file; the Date variable containes future dates for the appropriate Index. The Date variable gets imported into SAS as a character variable after I use the appropriate proc.

 

I would like to either a) import the variable into SAS as a numeric variable or b) convert the variable into numeric after I have imported it into SAS. Also, I would appreciate any thoughts on how I can deal with the issue that some of my values in the Date variable show up as mmm-yy, rather than yy-mmm.

 

I would appreciate any insight that you may have to offer.

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You can only read into a character variable; next use the position of the hyphen (determine with indexc()) to decide how to correct the order and drop the hyphen with substr(), so all entries are structured as MMMYY. After prepending "01" as day you can use input(chardate,date7.) to convert to a SAS date.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

You can only read into a character variable; next use the position of the hyphen (determine with indexc()) to decide how to correct the order and drop the hyphen with substr(), so all entries are structured as MMMYY. After prepending "01" as day you can use input(chardate,date7.) to convert to a SAS date.

evp000
Quartz | Level 8

I would import them as character then deal with them in SAS.  You can check the values and convert them depending on the source value. For instance you can check if the first character is numeric then create a date using the first value* as the year, and the second** as the month in the MDY function.  Conversely if the first character is a letter, use the first value as the month and the second as the year in the same function.  You'd have to supply a value for the day as mentioned in the previous answer. 

 

* scan(date, 1, '-');

** scan(date, 2, '-');

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