BookmarkSubscribeRSS Feed
noobs
Calcite | Level 5

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
Calcite | Level 5

Thanks!

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 7835 views
  • 0 likes
  • 4 in conversation