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!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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