| Valid in: | DATA step or PROC step |
| Category: | File-handling |
| Type: | Declarative |
You can use the GROUPFORMAT option in a BY statement only in a DATA step.
Using the GROUPFORMAT option in the DATA step ensures that BY groups that you use to create a data set match the BY groups in PROC steps that report grouped, formatted data.
data sedanTypes; set cars; by 'Sedan Types'n; if 'first.Sedan Types'n then type=1; run;
Using the NOTSORTED option is useful if you have data that falls into other logical groupings such as chronological order or categories.
proc format;
value range
low -55 = 'Under 55'
55-60 = '55 to 60'
60-65 = '60 to 65'
65-70 = '65 to 70'
other = 'Over 70';
run;
proc sort data=sashelp.class out=sorted_class;
by height;
run;
data _null_;
format height range.;
set sorted_class;
by height groupformat;
if first.height then
put 'Shortest in ' height 'measures ' height:best12.;
run;data Inventory;
length RecordID 8 Invoice $ 30 ItemLine $ 50;
infile datalines;
input RecordID Invoice ItemLine &;
drop RecordID;
datalines;
A74 A5296 Highlighters
A75 A5296 Lot # 7603
A76 A5296 Yellow Blue Green
A77 A5296 24 per box
A78 A5297 Paper Clips
A79 A5297 Lot # 7423
A80 A5297 Small Medium Large
A81 A5298 Gluestick
A82 A5298 Lot # 4422
A83 A5298 New item
A84 A5299 Rubber bands
A85 A5299 Lot # 7892
A86 A5299 Wide width, Narrow width
A87 A5299 1000 per box
;
data combined;
array Line{4} $ 60 ;
retain Line1-Line4;
keep Invoice Line1-Line4;
set Inventory;
by Invoice;
if first.Invoice then do;
call missing(of Line1-Line4);
records = 0;
end;
records + 1;
Line[records]=ItemLine;
if last.Invoice then output;
run;
proc print data=combined;
title 'Office Supply Inventory';
run;