BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
joon1
Quartz | Level 8
Hi Madam/Sir,

 

I would like to count the number of observations when ind_dir=1 in the same company (cikcode) and in the same year (annualreportdate). The following code was tried and printed. However, as shown in the excel sheet containing data, the whole observation per company-year was counted regardless whether ind_dir=1 or ind_dir=0. How can I fix the program to count the number of observations only when ind_dir=1 per company-year pair?


163 proc sql;
163! create table count1 as select*, count(ind_dir=1) as dirindsum from os5 group by
163! cikcode, annualreportdate; run;
NOTE: The query requires remerging summary statistics back with the original data.
NOTE: Table WORK.COUNT1 created, with 2474560 rows and 40 columns.

NOTE: PROC SQL statements are executed immediately; The RUN statement has no effect.
164
NOTE: PROCEDURE SQL used (Total process time):
real time 8:43.94
cpu time 1:09.04


165 proc print data=count1(obs=1000); var cikcode annualreportdate ind_dir dirindsum; run;

NOTE: There were 1000 observations read from the data set WORK.COUNT1.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.32 seconds
cpu time 0.31 seconds

 

Thank you very much for your help in advance

 

SIncerely,

Joon1

 
1 ACCEPTED SOLUTION

Accepted Solutions
hlnquynh
Obsidian | Level 7

Hope this help!

 

proc sql;
  create table count1 as

    select distinct cikcode, annualreportdate, count(*) as dirindsum

    from os5 where ind_dir=1

    group by cikcode, annualreportdate

  ;

quit;

View solution in original post

1 REPLY 1
hlnquynh
Obsidian | Level 7

Hope this help!

 

proc sql;
  create table count1 as

    select distinct cikcode, annualreportdate, count(*) as dirindsum

    from os5 where ind_dir=1

    group by cikcode, annualreportdate

  ;

quit;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 529 views
  • 0 likes
  • 2 in conversation