Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

data row arrangment

Status
Not open for further replies.

prakash2000

Technical User
Oct 23, 2009
8
IN
im new in SAS,

I have the following format dataset

UID Group value
--- ------- -------
1 1 8
2 1 2
3 1 8
4 1 4
5 1 2
6 1 2
7 1 4
8 2 2
9 2 8
10 2 8
11 2 2
12 2 4
13 2 8
14 2 2

I need the following format

UID Group value
--- ----- ------
1 1 8
3 1 8
2 1 2
5 1 2
6 1 2
7 1 4
8 2 2
11 2 2
14 2 2
9 2 8
10 2 8
13 2 8
12 2 4


how to arrange value data,based on group value?

thanks in advance

prakash
 
Prakash,
I don't understand how you want the dataset reformatted, but you can use the sort procedure to resort your data.
Code:
proc sort data=yourdataset;
by group value;
run;

By default it sorts ascending, but you can change that by putting "descending" in front of the variable you want to sort.

Dave
 
Thanks for ur msg dblan, but my problem little different from sort.

kindly look at my data.

" my first row value=8. here i need to get all 8's with in a group.and next value=2 then get all 2's finally 4's."

how to implement this mechanism into all the groups?


kindly let me know it's urgent

thanks
prakash

 
prakash,
Do you need different sort orders for the different groups?
In your first example, Group 1's values are 8,2,then 4.
Then Group 2's values are sorted 2,8, then 4.

Here a way to sort just based on the Value column:
You can create a column to sort with, then drop it once the data is sorted.
Code:
data have;
input UID Group Value ;
datalines;
1        1         8
2        1         2
3        1         8
4        1         4
5        1         2
6        1         2
7        1         4
8        2         2
9        2         8
10       2         8
11       2         2
12       2         4
13       2         8
14       2         2
;
run;
data want;
set have;
select(value);
  when('8') n=1;
  when('2') n=2;
  when('4') n=3;
end;
run;
proc sort data=want;
by Group n;
run;
data want (drop=n);
set want;
run;
If you need different sort order based on Groups, you'll have add that logic during the creation of the "n" variable that is used to sort.

Hope this helps,
Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top