BookmarkSubscribeRSS Feed
dlazer1
Calcite | Level 5

Hi,

 

I have my data set and need to do a count for unique analysts following a company. They are given random numbers but all I need is a final count. 

 

So far I have this but it is not working.

Thank you for your help!

 

proc means data=rawdata.ibes noprint;
count=1 if analys="";
var count;
by cusip fpedats;
output out=forecastdate sum(count)=total;
run;

 

 

4 REPLIES 4
Norman21
Lapis Lazuli | Level 10

The following might help you find an answer:

 

"Count the distinct values of a variable"

 

http://support.sas.com/kb/36/898.html

Norman.
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

Reeza
Super User

There are two methods illustrated here:

 

/*This demonstrates how to count the number of unique occurences of a variable
across groups. It uses the SASHELP.CARS dataset which is available with any SAS installation.
The objective is to determine the number of unique car makers by origin/

Note: The SQL solution can be off if you have a large data set and these are not the only two ways to calculate distinct counts.
If you're dealing with a large data set other methods may be appropriate.*/

*Count distinct IDs;
proc sql;
create table distinct_sql as
select origin, count(distinct make) as n_make
from sashelp.cars
group by origin;
quit;

*Double PROC FREQ;
proc freq data=sashelp.cars noprint;
table origin * make / out=origin_make;
run;

proc freq data=origin_make noprint;
table origin / out= distinct_freq;
run;

title 'PROC FREQ';
proc print data=distinct_freq;
run;
title 'PROC SQL';
proc print data=distinct_sql;
run;

https://github.com/statgeek/SAS-Tutorials/blob/master/count_distinct_by_group

dlazer1
Calcite | Level 5

Thank you. I now used a proc freq as follows.

 

proc freq data=sortedibes noprint order=freq;
tables CUSIP*ANALYS*FPEDATS /out=counts;
run;

proc means data=counts max;
class CUSIP ANALYS;
var COUNT;
run;

 

How do I get the total value for unique ANALYS for a particular cusip on a particular date with is FPEDATS?

 

Thanks! 

Reeza
Super User

Use a WHERE statement to restrict your output.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1483 views
  • 0 likes
  • 3 in conversation