See Crunch Automation basics for more information.
The SET DATES command lets you set date attributes on each category for categorical variables. For example, you have a categorical variable that represents Wave or Quarter and you need to set a date against each category. This enables you to use the categorical variables in time series analysis. The concept is described in detail in the Defining survey wave variables article.
When indicating each individual category, all dates must be indicated with valid ISO-8601 format strings. You can be precise to the year ("YYYY"), month ("YYYY-MM"), or day ("YYYY-MM-DD").
You can set the dates for multiple variables at once (provided they have the same categories).
You have the option to explicitly specify the dates (WITH) or to borrow the dates from the categories names (FROM NAMES).
FROM NAMES will validate that all categories have valid date strings. It will throw an error if the names are not in a valid ISO-8601 format.
In all cases, the numeric values for the categories will be set to NULL.
SET DATES alias, ... , alias WITH code|"label" = "date", ... code|"label" = "date"; SET DATES alias, ... , alias FROM NAMES FORMAT label;
The following describes two example scenarios:
- Setting the date values based on a wave variable
- Borrowing the date from the category labels
Setting the date values based on a wave variable
Suppose we had a wave variable (each wave was a week)—we could then set the date with the end point of each week:
SET DATES wave WITH "Wave 1" = "2019-01-01", "Wave 2" = "2019-01-08", "Wave 3" = "2019-01-15", "Wave 4" = "2019-01-22", "Wave 5" = "2020-01-29";
The result is as follows (in the Variable Properties):
Borrowing the date from the category labels
Suppose we had a categorical variable (alias ‘date’) for which the category labels were the month of an interview. The labels are in the format YYYY-MM, so we can borrow those labels and use them to set the date:
SET DATES month FROM NAMES FORMAT "%Y-%m";