Hi, below is an example of the data I have (in reality about 20000 entries and many more variables).
Identifier | Var_1 | Var_2 | Var_3 |
1 | ZN | ZN | DS |
2 | ZN | DS | FD |
3 | DS | DS |
|
4 | FD | FD | ZN |
I used proq freq to find frequencies of 'ZN', 'DS' and 'FD' for Var_1, Var_2 and Var_3 seperately like so:
proc freq data=rehab order=freq;
tables Var_1;
run;
I want to find the freq. of 'ZN' and so on in all three variables, but not counting them multible times. As in "so many have 'ZN' at all and so on
I cant seem to grasp it - is it possible oh clever internet-people?
Bad dataset structure leads to complicated code. See Maxim 19.
Transpose first, get rid of the duplicates, FREQ:
proc transpose data=have out=long (keep=identifier col1);
by identifier;
var var_:;
run;
proc sort data=long nodupkey;
by identifier col1;
run;
proc freq data=long;
tables col1;
run;
Bad dataset structure leads to complicated code. See Maxim 19.
Transpose first, get rid of the duplicates, FREQ:
proc transpose data=have out=long (keep=identifier col1);
by identifier;
var var_:;
run;
proc sort data=long nodupkey;
by identifier col1;
run;
proc freq data=long;
tables col1;
run;
Thank you
The dataset has many more facets, and it is also relevant how many have 1, 2 or three and which have dublicates.
Transposing a copy of the dataset for anwering specific questions does however seem to be the answer, and your code did work for that so thank you very much!!
Hi @miajoe, glad to see that it worked. Did @Kurt_Bremser solve your problem? If so, please mark this as solved and that @Kurt_Bremser provided the solution.
This will help others in the future that may run into the same issues.
Thank you!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.