BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello,

I am relatively new to using SAS beyond the routine PROC proceedures.

I am trying to create a simple frequency distribution chart, but on grouped data.
In other words, I want to define 10 groups, say 0-10, 10-20, ..... 90-100
and then count how many of the originial observations are in each of these 10 groups.
Is there an easy way to do this using PROC UNIVARIATE or such?
6 REPLIES 6
Doc_Duke
Rhodochrosite | Level 12
The easiest way is to create a FORMAT (see PROC FORMAT for syntax) and then use PROC FREQ to get your frequencies.

Doc Muhlbaier
Duke
DanielSantos
Barite | Level 11
Doc's suggestion (PROC FORMAT+PROC FREQ) is just right.

More solutions are available, but all very similar, and all within a two pass execution.

Another one, would be two SQL queries or one SQL query with sub-query, (which is still a two pass solution), with the inner query producing some temporary GROUP_ID for each row (say GROUP_ID=1 case when 0-10, GROUP_ID=2 case when 10-20, ...), and the outer query counting row for each GROUP_ID.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt.
deleted_user
Not applicable
I am surprised SAS has not incoporated an easier way to do this.

...... are you all enjoying you legal drugs in Protugal.... just kidding. Wouldn't make a difference to me, but it makes sense economically.
deleted_user
Not applicable
.... does anybody know of an explicit (simple) example where this is done. I am not familiar with the SQL syntax or even the FORMAT syntax.

....... it's no big deal, but I would like to learn it in case I come across it again.
DanielSantos
Barite | Level 11
But, it is indeed an easy procedure.

For example:

proc sql;
select GROUP_ID, count(*) as COUNT from (
select int(VALUE/10) as GROUP_ID from INPUT
) group by GROUP_ID;
quit;

int(VALUE/10) will return the integer value of VALUE/10, so
0 =< VALUE < 10 => GROUP_ID = 0
10 =< VALUE < 20 => GROUP_ID = 1
etc...

And by the way, drugs are still pretty illegal here.
It was discussed some time ago, but it was a no go idea.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt.
deleted_user
Not applicable
Wow, that's awesome.

I thought I heard on NPR that they decriminalized all drugs in Protugal???
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1843 views
  • 0 likes
  • 3 in conversation