BookmarkSubscribeRSS Feed
duel
Calcite | Level 5

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,....

7 REPLIES 7
Kurt_Bremser
Super User

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.

duel
Calcite | Level 5

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"

Kurt_Bremser
Super User

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"


 

duel
Calcite | Level 5

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.

duel
Calcite | Level 5

get it. Found a way! Thanky anyway!

mkeintz
PROC Star

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".

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

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.

  

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 7 replies
  • 573 views
  • 1 like
  • 4 in conversation