I have a dataset whose structure is similar to:
person obs colour
Dave 1 red
Dave 1 green
Dave 1 blue
Mary 1 blue
Mary 1 red
Mary 2 green
There could be anywhere between 1 and 13 colours for each person-obs combination
i would like to transpose this to one row per person-obs combination with column names matching the colour variable value and a flag to indicate which colours matched the person-observation combo:
Person Obs Red Blue Green
Dave 1 1 1 1
Mary 1 1 1 0
Mary 2 0 0 1
I can use the retain statement to generate and initialise my colour column names, and then loop through a group of person-obs combinations until i hit last.obs. I can read in the value of the variable colour into a macro variable within a datastep, and can use the resolve function to get this 'value', but i cannot find a way to use the string value of this macro variable to assign a '1' flag to the column name that corresponds to this string value:
call symput('mac_colour', colour);
colourvar = compress(resolve('&mac_colour'));
How do i use the string value of colourvar to set a column name equal to the value of colourvar to 1?
Any method i try doesn't like have a function on the left of an assign statement.
Any ideas? Cheers in advance
person obs colour
Dave 1 red
Dave 1 green
Dave 1 blue
Mary 1 blue
Mary 1 red
Mary 2 green
There could be anywhere between 1 and 13 colours for each person-obs combination
i would like to transpose this to one row per person-obs combination with column names matching the colour variable value and a flag to indicate which colours matched the person-observation combo:
Person Obs Red Blue Green
Dave 1 1 1 1
Mary 1 1 1 0
Mary 2 0 0 1
I can use the retain statement to generate and initialise my colour column names, and then loop through a group of person-obs combinations until i hit last.obs. I can read in the value of the variable colour into a macro variable within a datastep, and can use the resolve function to get this 'value', but i cannot find a way to use the string value of this macro variable to assign a '1' flag to the column name that corresponds to this string value:
call symput('mac_colour', colour);
colourvar = compress(resolve('&mac_colour'));
How do i use the string value of colourvar to set a column name equal to the value of colourvar to 1?
Any method i try doesn't like have a function on the left of an assign statement.
Any ideas? Cheers in advance