Desktop productivity for business analysts and programmers

combining multiple value with distinct value

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 340
Accepted Solution

combining multiple value with distinct value

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

 


Accepted Solutions
Solution
‎11-04-2016 06:16 PM
Trusted Advisor
Posts: 1,479

Re: combining multiple value with distinct value

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


All Replies
Solution
‎11-04-2016 06:16 PM
Trusted Advisor
Posts: 1,479

Re: combining multiple value with distinct value

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;

Super User
Posts: 5,369

Re: combining multiple value with distinct value

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;

Super User
Posts: 11,134

Re: combining multiple value with distinct value

And a different proc as an option:


proc tabulate data=have;
   class var1;
   table var1='',
         n="Sessions Running"
   ;
run;
Super Contributor
Super Contributor
Posts: 340

Re: combining multiple value with distinct value

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 272 views
  • 2 likes
  • 4 in conversation