BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
miajoe
Fluorite | Level 6

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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;
miajoe
Fluorite | Level 6

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!!

 

 

 

maguiremq
SAS Super FREQ

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!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1057 views
  • 0 likes
  • 3 in conversation