DATA Step, Macro, Functions and more

Groups of Data

Reply
Regular Contributor
Posts: 212

Groups of Data

Hi, 

I need a way to show just like the freq procedure the table below:

ID VALUE

1   10

2   10

3   10

4   30

 

I'd like to establish, if value is lower than 20 then it will represent a percentage, and so on.

I know there is a proc step to do this, i don't remember the name.

 

You guys have any idea ?

 

Thanks

 

 

Contributor ndp
Contributor
Posts: 61

Re: Groups of Data

Posted in reply to DartibaliRodrigo

create a format using proc format and then use it in proc freq.

Regular Contributor
Posts: 212

Re: Groups of Data

[ Edited ]

Actualy i need the proc step.

What i need is, establish tracks, just like:

 

if the value is lower than 10 then all values that are lower then 10 are in this group

if the value is lower than 20 then all values that are lower then 20 are in this group

if the value is lower than 30 then all values that are lower then 30 are in this group

 

I think there is a way to do this with proc tabulate but i don't remember how.

 

Valued Guide
Posts: 860

Re: Groups of Data

Posted in reply to DartibaliRodrigo

You can either write it out using if - then or use proc format:

 

data have;
input ID VALUE;
cards;
1   10
2   15
3   20
4   30
;

proc format;
    value new low-10 = 1
              11-19  = 2
              20-29  = 3
              30-high= 4;
run;

data want;
set have;
if value < 11 then group = 1;
if 11 <= value < 20 then group = 2;
if 20 <= value < 30 then group = 3;
if value >= 30 then group = 4;
new_var = value;
format new_var new.;
run;

Contributor ndp
Contributor
Posts: 61

Re: Groups of Data

Posted in reply to DartibaliRodrigo

here is what i was talking about but there are plenty of other ways. You can adjust as per your needs.

 

data test;
input ID VALUE;
datalines;
1   10
2   20
3   10
4   30
run;

proc format;
	value grp low - 10 = '1'
			  10 <- 20 = '2'
			  20 <- high = '3'
	;
run;	

proc freq data=test;
	tables value;
	format value grp.;
run;

.  

Valued Guide
Posts: 860

Re: Groups of Data

Posted in reply to DartibaliRodrigo

You should give an example of the data you have and what you want to see.  It's not perfectly clear what you are looking for here.

Ask a Question
Discussion stats
  • 5 replies
  • 208 views
  • 2 likes
  • 3 in conversation