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,....
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.
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"
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"
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.
get it. Found a way! Thanky anyway!
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".
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.
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.