BookmarkSubscribeRSS Feed
noobs
Fluorite | Level 6

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

4 REPLIES 4
PaigeMiller
Diamond | Level 26

untested code

proc sql noprint;

    select distinct(week) into :week_distinct from have;

quit;

--
Paige Miller
pradeepalankar
Obsidian | Level 7

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

noobs
Fluorite | Level 6

Thanks!

amitr4620
Calcite | Level 5
How to store no of row in a variable without processing sql

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 4 replies
  • 9082 views
  • 0 likes
  • 4 in conversation