Hi everyone,
Here is a sample of my data.
The OBS is a unique individual.
Each column is a state that they have visited. 1=yes, 0=no
I'd like to to figure out the various combinations of states.
For example: OBS 1 and 7 has visited NewYork and Texas so NewYorkTexas would be 2
I'd like to do that for all possible combinations. Any suggestion as to how to begin?
OBS | NewYork | California | Texas | NewJersey | Washington |
1 | 1 | 0 | 1 | 0 | 0 |
2 | 0 | 1 | 1 | 0 | 0 |
3 | 0 | 0 | 1 | 0 | 1 |
4 | 1 | 1 | 0 | 0 | 1 |
5 | 0 | 0 | 0 | 0 | 1 |
6 | 0 | 1 | 1 | 0 | 0 |
7 | 1 | 0 | 1 | 0 | 1 |
8 | 1 | 1 | 0 | 1 | 1 |
9 | 1 | 1 | 1 | 0 | 0 |
10 | 1 | 1 | 0 | 1 | 1
|
An easy way would be to string together all the flags:
all_locations = cat(NewYork, California, Texas, NewJersey, Washington);
You need to preserve this logic, so you know which position represents which state.
Then count:
proc freq data=have;
tables all_locations;
run;
An easy way would be to string together all the flags:
all_locations = cat(NewYork, California, Texas, NewJersey, Washington);
You need to preserve this logic, so you know which position represents which state.
Then count:
proc freq data=have;
tables all_locations;
run;
That was a astounding answer! THANK YOU!
Hi @hwangnyc Can you post the output for the sample you provided for the benefit of the wider audience. Thank you!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.