DATA Step, Macro, Functions and more

SAS count of records grouping by a varable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

SAS count of records grouping by a varable

[ Edited ]

In the attached data set , I am trying to find the hospital that has got more number of patients? The solution that  have below seems to be long. Can someone please suggest the best/ easy way to solve this? Thank you.

 

 

proc means data=mylib1.claim nway order =freq;

class Hospid;

var BenefUserID;

output out =temp;

 

data temp1;

set temp;

where _stat_= "N";

drop _freq_ _type_ _stat_;


Accepted Solutions
Solution
‎06-15-2017 02:37 PM
PROC Star
Posts: 551

Re: SAS count of records grouping by a varable

Use DROP like this

 

proc means data=claim nway order=freq noprint;
  class Hospid;
  var BenefUserID;
  output out=temp(drop = _FREQ_ _TYPE_) n=n;
run;

View solution in original post


All Replies
PROC Star
Posts: 551

Re: SAS count of records grouping by a varable

[ Edited ]

I don't see any attached dataset? Please provide sample data in the form of a datastep

Occasional Contributor
Posts: 8

Re: SAS count of records grouping by a varable

Sorry, this s how the sample data looks like:

BenefUserIDHospId
108HopID-399
114HopID-279
117HopID-32
141HopID-45
147HopID-258
148HopID-846
159HopID-499
186HopID-490
192HopID-399
194HopID-138
195HopID-399
224HopID-13
242HopID-231
247HopID-45
250HopID-154
Super User
Super User
Posts: 7,401

Re: SAS count of records grouping by a varable

Seems fine to me other than your missing a "run;" at the end of each step - not required, but good practice.  What do you think is long about it, you don't need the second statement, just wrap that into further processing.

No dataset attached by the way, and post test data in the form of a datastep anyway.

Occasional Contributor
Posts: 8

Re: SAS count of records grouping by a varable

Thank you for your response. Sorry missed data earlier.

I provided the sample data in the previous post now.

Do you mean  dont need data step? If I only use the first proc step,  get N, Mean, median and standard deviation in the result set. How do  ignore them and only keep the number of observations/ count for each hospital?

Super User
Super User
Posts: 7,401

Re: SAS count of records grouping by a varable

You can select summary stats on the output step (and add noprint to supress the text output) - note below how I present test data, please provide like this in future.

data claim;
  input BenefUserID	HospId $;
datalines;
108	HopID-399
114	HopID-279
117	HopID-32
141	HopID-45
147	HopID-258
148	HopID-846
159	HopID-499
186	HopID-490
;
run;

proc means data=claim nway order=freq noprint;
  class Hospid;
  var BenefUserID;
  output out=temp n=n;
run;
Occasional Contributor
Posts: 8

Re: SAS count of records grouping by a varable

Thank you, I will keep the dataset in mind in the future. 

Btw, I still get _type_ and _freq_ columns in the outout screen. How do I get rid of them and only show Hospital and number of observations? Can I use drop here?

Solution
‎06-15-2017 02:37 PM
PROC Star
Posts: 551

Re: SAS count of records grouping by a varable

Use DROP like this

 

proc means data=claim nway order=freq noprint;
  class Hospid;
  var BenefUserID;
  output out=temp(drop = _FREQ_ _TYPE_) n=n;
run;
☑ This topic is SOLVED.

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

Discussion stats
  • 7 replies
  • 124 views
  • 0 likes
  • 3 in conversation