Desktop productivity for business analysts and programmers

Store distinct count in macro variable

Reply
Contributor
Posts: 73

Store distinct count in macro variable

Hello EG Users,

How can one store value that represents distinct rows of a variable in dataset into macro?

Data have;

Week   Activity

5          Pingpong

10          Badminton

15          Chess

I would like to count distinct values for Week, which is 3 in this case and store it in macro Week_Distinct.

I would appreciate your instructions on how to achieve that?

Regards,

Dhanashree

Trusted Advisor
Posts: 1,516

Re: Store distinct count in macro variable

untested code

proc sql noprint;

    select distinct(week) into :week_distinct from have;

quit;

Frequent Contributor
Posts: 106

Re: Store distinct count in macro variable

hi,

correct sql should be:

Data have;

input Week Activity :$;

cards;

5 Pingpong

10 Badminton

15 Chess

;

proc sql ;

select  count(distinct week) into :week_distinct from have;

quit;

238  %put &week_distinct;

3

Contributor
Posts: 73

Re: Store distinct count in macro variable

Thanks!

Ask a Question
Discussion stats
  • 3 replies
  • 787 views
  • 0 likes
  • 3 in conversation