- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have a column on my dataset that has date values, but the variable is Catregorical. I am looking for a way to get the month values. For example, the data I have is Dec 08 2022 (categorical). I would like to get the 08, using VA interface. I'd use Calculated Item, and use Text operators but then they require numerical inputs. So, this idea didn't work.
Can I achieve what I am trying to do in VA? If yes, how?
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
This is a common issue, especially if you are importing CSV/TSV data. The Parse() operator is what you need.
Parse
interprets a numeric or datetime value from the input string. Click the format field to select the format that is used to interpret the string. The output from the Parse operator is either a number or a datetime value, depending on the format that you select.
For example, Parse('15JAN2013', 'DATE9.')
returns 15JAN2013 as a date value.
Let us know if that helps,
Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sam,
Thanks for the suggestion. Actually, I tried it but then all I had in the calculated item was missings. Here is how I created the Calculated Item using Parse:
This is the result on the left hand side column (all missing) created based on the right hand side column.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
It looks like your date values have spaces in them: 01 JAN 2023
You might try different formats to see if there is one that will parse this.
You can also try wrapping the date value in the RemoveBlanks() operator.
That would look something like this:
Parse(RemoveBlanks('Date'n, _All_), 'Date9.')
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sam,
Thank you again! I understand the logic you suggested. I applied the Remove Blanks. Then I applied Parse but still all I have is missings.Do you have any idea why this could be happenning?
Result:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Those strings are not in a style that the DATE informat will understand. It wants the day of the month first.
Try using the anydtdte11. informat instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Tom wrote:
Those strings are not in a style that the DATE informat will understand. It wants the day of the month first.
Try using the anydtdte11. informat instead.
Yes, this should work and should not require RemoveBlanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sam,
I am sorry, but I still do get the missings. Please let me know if you can see any reasons why his is happenning.
Result:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Try parsing the original date.
Also, just for a sanity check, please try this:
Parse('JAN 23 2023', 'ANYDTDTE11.')
That is, just parse this one value and see if it returns 23JAN2023 as we would expect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sam,
Yes, I'm applying anydtdte11 format to "BlanksRemoved", which is the value that has had RemoveBlanks() applied to it....
Then I tried parsing the original date (with blanks) with 'ANYDTDTE11.', and it worked. Thank you so much!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Great! Thanks for letting us know 🙂