BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
woo
Barite | Level 11 woo
Barite | Level 11

Hello friends, can someone plz help,

 

have

var1        var2

user1      sessionXYZ

user1      sessionABC

user1      sessionGYAKFJ

user2      sessionSDFKJ

user3      sessionsfljasfgljk

user3      sessionfvksjfvnsjn

 

want

user1 has 3 seession running

user2 has 1 session running

user3 has 2 session running

 

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

Option 1:

proc freq data=have; by var1; run

you will get the frequency of each user in the dataset;

 

Option 2:

 

    data want;

      set have;

        by var1;    /* assumed data is sorted */

             retain counter ;

             if first.var1 then  counter = 1; else counter+1

             if last.var1 then 

                 /* either */ output;

                 /* or */  put var1 'has ' counter ' sessions running';

run;

View solution in original post

4 REPLIES 4
Shmuel
Garnet | Level 18

Option 1:

proc freq data=have; by var1; run

you will get the frequency of each user in the dataset;

 

Option 2:

 

    data want;

      set have;

        by var1;    /* assumed data is sorted */

             retain counter ;

             if first.var1 then  counter = 1; else counter+1

             if last.var1 then 

                 /* either */ output;

                 /* or */  put var1 'has ' counter ' sessions running';

run;

Astounding
PROC Star

If it's the report that you are after, you can extend the idea already suggested:

 

proc freq data=have;

tables var1 / noprint out=sessions;

run;

 

data _null_;

set sessions;

file print notitles;

if count > 1 then put var1 'has ' count 'sessions.';

else put var1 'has 1 session.';

run;

ballardw
Super User

And a different proc as an option:


proc tabulate data=have;
   class var1;
   table var1='',
         n="Sessions Running"
   ;
run;
woo
Barite | Level 11 woo
Barite | Level 11

thank you all...appreciate your time...

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
  • 944 views
  • 2 likes
  • 4 in conversation