count only one oberservation per variable

Reply
Occasional Contributor
Posts: 8

count only one oberservation per variable

Hi I have the following data

 

id          var1     var2

10         1           2

10         1           2

10         1           2

10          1          2

15         2          2

15         2          2

15         2          2

16         1         1 

16         1         1 

16         1         1 

16         1         1 

 

I want to count how many ID`s "said" var1 and var2 but I want to have just one observation per ID.

How I can do this easily?

With proc freq I get which Id said was but I want like 1000 ID's said var1 is 1 and var2 is 1,....

Super User
Posts: 10,592

Re: count only one oberservation per variable

What do you mean by "say"?

 

Please post an example for the expected output.

And present your example data in a data step:

data have;
input id var1 var2;
cards;
10 1 2
10 1 2
10 1 2
10 1 2
15 2 2
15 2 2
15 2 2
16 1 1
16 1 1
16 1 1
16 1 1
;
run;

Anybody can now recreate the dataset with a simple copy/paste and submit.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 8

Re: count only one oberservation per variable

Posted in reply to KurtBremser

every id is a person who had to answer questions

var1 =question 1 (1=yes 2=no),....

Thats the reason that I wrote "say or said"

Super User
Posts: 10,592

Re: count only one oberservation per variable

Still does not make any sense. Please post an example of the result, based on the example dataset.


duel wrote:

every id is a person who had to answer questions

var1 =question 1 (1=yes 2=no),....

Thats the reason that I wrote "say or said"


 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 8

Re: count only one oberservation per variable

Posted in reply to KurtBremser

I want to count the answers (don't want a new variable)

 

Var1: 1000 persons (ID) answered 1(yes) and 1500 2(no).

same for Var2

 

I could do it with proc freq but I have a lot of double or multiple ID's and I just want one oberservation per ID.

Occasional Contributor
Posts: 8

Re: count only one oberservation per variable

get it. Found a way! Thanky anyway!

Trusted Advisor
Posts: 1,395

Re: count only one oberservation per variable

Given your sample data has no within-id variation for var1 and var2, you should really title your topic as "count only  one observation per id", not "per variable".

Super User
Posts: 13,942

Re: count only one oberservation per variable

a guess: Does this get all close to what you want???

 

Proc freq data=junk ;

  tables id*var1*var2 /missing list;

run;

 

HOWEVER any ID that has more than one value for var1 and/or var2 will have one row per combination of var1 and var2 values. If you don't want that show exactly what you expect your output to look like. And if you have any ID with different combinations of var1 and var2 include them.

  

Ask a Question
Discussion stats
  • 7 replies
  • 141 views
  • 1 like
  • 4 in conversation