Proc SQL help

Accepted Solution Solved
Reply
Contributor
Posts: 53
Accepted Solution

Proc SQL help

Can someone explain to me what this code is doing?

 

PROC SQL;
CREATE TABLE summary AS
SELECT DISTINCT id, COUNT(id) AS fuentries
FROM EDB.event
GROUP BY id;
QUIT;

 

What is fuentries?

 

Thanks!

 


Accepted Solutions
Solution
‎04-21-2016 10:10 AM
Respected Advisor
Posts: 4,816

Re: Proc SQL help

This query calculates the number of observations for each id in table EDB.event . You could replace count(id) with count(*) and get the same result, except for the case where id is missing. In that special case, count(id) will be 0 and count(*) will be the real number of observations.

 

fuentries is the name given to the variable containing the counts.

 

The DISTINCT keyword is redundant in this query.

PG

View solution in original post


All Replies
Solution
‎04-21-2016 10:10 AM
Respected Advisor
Posts: 4,816

Re: Proc SQL help

This query calculates the number of observations for each id in table EDB.event . You could replace count(id) with count(*) and get the same result, except for the case where id is missing. In that special case, count(id) will be 0 and count(*) will be the real number of observations.

 

fuentries is the name given to the variable containing the counts.

 

The DISTINCT keyword is redundant in this query.

PG
Contributor
Posts: 53

Re: Proc SQL help

Thanks for the response. I'm having difficulting underinstand what my fuentries is. Can you tell me if I'm interperting this correctly:

 

 

proc freq data=summary; tables fuentries; run;

Untitled.png

 

There are 132 IDs with a count of 1?

Respected Advisor
Posts: 4,816

Re: Proc SQL help

Right.

 

proc sql;

select id from summary where fuentries=1;

quit;

 

to see them.

PG
Contributor
Posts: 53

Re: Proc SQL help

Thanks so much PG!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 298 views
  • 0 likes
  • 2 in conversation