Hi,
I have a categorical variable that looks like this.
I would like to convert it to the date format so that I will create another variable to take the month and year part, looks like this:
I tried the parsing:
But I get missing values. What can I do in VA to solve this?
Thanks!
Hi,
I had a cave a categorical variable that has date and time values, how can I remove the time part and have the date part only?
e.g. From this:
To this:
Thank you!
Hey @znhnm! The day of the week is what's causing your issue. anydtdte cannot parse that particular pattern, but it will parse the string if you remove the day of the week. You can fix this by removing the first word:
parse(removeword('CatDateTime'n, 1), 'anydtdte32.')
Note that anydtdte returns a date while anydtdtm returns a datetime. If you return a datetime, you can still format it as a month and retain the original datetime data by duplicating the column.
Another option would be to use the NLDATMWw informat as part of your data preparation to read in the values as SAS datetime values. After that you can apply formats in VA.
Thank you so much for the reply. I tried the RemoveWord but I get missing values so apllying Parsing afterwards is not giving the result I wanted.
Here it is:
And that expression is giving you a missing value for every row? It looks like it should work. But what if you change the Result Type to DateTime? Even though your desired result is a date, you might need to make a DateTime value and the apply a Date format to it.
If that doesn't help, what happens if you substitute a single value for the CatDateTime variable?
Like so:
Thanks so much for letting us know, glad to hear this is working like you want it to now.
I have had odd things happen in my report state sometimes. If a calculated item is used in anything (calculations, report objects, etc) generally you can't change the data type or format, but I'm not sure if that could have been the case here.
Thanks,
Sam
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.
Find more tutorials on the SAS Users YouTube channel.