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???

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
  • 6 replies
  • 799 views
  • 0 likes
  • 3 in conversation