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.
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.
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.
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, '-');
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.