BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

   mr_nbr  id
   123     001
   123     002
   234     003
   456     004
   456     005
   456     006

how to show that mr_nbr 123 has 2 different id's,456 has 3 different id's

and how to display that out of 3 different mr_nbrs there are  2 mr_nbrs that have different id's i.e 60% have multiple id's  and reverse i.e how id and mr_nbr related

3 REPLIES 3
art297
Opal | Level 21

data have;

  input mr_nbr  id $;

  cards;

   123     001

   123     002

   234     003

   456     004

   456     005

   456     006

;

proc sql;

  select distinct mr_nbr, count(id) as how_many

    from have

      group by mr_nbr

  ;

quit;

SASPhile
Quartz | Level 8

Is there a better way to know the percent of mr_nbr that have more than one id?in this case out three mr_nbr 2 have more than one id. which is 66.6%

Peter_C
Rhodochrosite | Level 12

Do you seek two answers?

had provided the first.

Adapt it to create a summary table that can be analysed with proc freq which provides those cumulative percentages more conveniently than tabulate

proc sql;

CREATE TABLE summary1 AS

  select  mr_nbr, count(id) as how_many

    from have

      group by mr_nbr

  ;

quit ;

* generate cumulative frequency report ;

Proc freq data= summary1 ;

Table how_many ;

run ;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 846 views
  • 1 like
  • 3 in conversation