Proc Forms :
The FORMS procedure produces labels for envelopes, mailing labels, external tape labels, file cards, and any other printer forms that have a regular pattern.
We should write at least one LINE statement.
Syntax:-
PROC FORMS <option(s)>;
BY <DESCENDING> variable-1<…<DESCENDING> variable-n> <NOTSORTED>;
FREQ variable;
LINE line-number variable(s) </ option(s)>;
Options:-
DATA=Specify the input data set.
FILE=Identify an external file for PROC FORMS to write to file location.
Control the dimensions of a form
LINES=Specify the number of lines in the form unit.
WIDTH=Specify the number of columns across the form unit.
Control the placement of the forms
ACROSS=Specify the number of form units to print across the page.
BETWEEN=Specify the number of spaces to print between form units.
DOWN=Specify the number of lines to skip on a page before printing the first form unit.
INDENT=Specify the number of spaces to indent before printing the first form unit in each row.
NDOWN=Specify the number of form units to print down the page.
PAGESIZE=Specify the number of lines on a page of forms.
SKIP=Specify the number of lines to skip between form units.
Control the number of each form unit that PROC FORMS prints
COPIES=Specify the number of form units to produce for each observation in each set of form units
SETS=Specify the number of sets of form units to produce.
CC Control the placement of page-eject characters
ALIGN=Specify the number of lines of dummy form units to print
Examples:-
Options Pagesize=60 Linesize=64 nodate pageno=1;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.txt’;
Proc forms data=sashelp.class(obs=10) file=labels align=0;
Line 1 name;
Line 2 sex;
Line 3 age;
Line 4 height;
Line 5 weight;
Run;
WIDTH=Specify the number of columns across the form unit. (Range 1-255)
Options Pagesize=60 Linesize=64 nodate pageno=1;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.txt’;
Proc forms data=sashelp.class(obs=10) file=labels align=0 width=15;
Line 1 name;
Line 2 sex;
Line 3 age;
Line 4 height;
Line 5 weight;
Run;
ACROSS=Specify the number of form units to print across the page. (Range 1-200)
Options Pagesize=60 Linesize=64 nodate pageno=1;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=sashelp.class(obs=12) file=labels align=0 width=15 across=4;
Line 1 name;
Line 2 sex;
Line 3 ages;
Line 4 height;
Line 5 weight;
Run;
BETWEEN=Specify the number of spaces to print between form units. (Range 1-200)
Options Pagesize=60 Linesize=64 nodate pageno=1;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=sashelp.class(obs=12) file=labels align=0 width=15 across=2 between=10;
Line 1 name;
Line 2 sex;
Line 3 age;
Line 4 height;
Line 5 weight;
Run;
DOWN=Specify the number of lines to skip on a page before printing the first form unit.
Options Pagesize=60 Linesize=64 nodate pageno=1; (Range 1-200)
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=sashelp.class(obs=12) file=labels align=0 width=15
across=2 between=10 down=5;
Line 1 name;
Line 2 sex;
Line 3 age;
Line 4 height;
Line 5 weight;
Run;
NDOWN=Specify the number of form units to print down the page.
Options Pagesize=60 Linesize=64 nodate;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=sashelp.class file=labels ndown=4;
Line 1 name;
Line 2 sex;
Line 3 age;
Line 4 height;
Line 5 weight;
Run;
PAGESIZE=Specify the number of lines on a page of forms
Options Pagesize=60 Linesize=64 nodate;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=sashelp.class(obs=12) file=labels pagesize=5;
Line 1 name;
Line 2 sex;
Line 3 age;
Line 4 height;
Line 5 weight;
Run;
SKIP=Specify the number of lines to skip between form units (Range 1-200)
Options Pagesize=60 Linesize=64 nodate pageno=1;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=sashelp.class(obs=12) file=labels align=2 skip=5;
Line 1 name;
Line 2 sex;
Line 3 age;
Line 4 height;
Line 5 weight;
Run;
COPIES=Specify the number of form units to produce for each observation in each set of form units
Options Pagesize=60 Linesize=64 nodate pageno=1;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=sashelp.class(obs=12) file=labels align=0 width=15
across=2 between=10 copies=3;
Line 1 name;
Line 2 sex;
Line 3 age;
Line 4 height;
Line 5 weight;
Run;
SETS=Specify the number of sets of form units to produce.
Options Pagesize=60 Linesize=64 nodate pageno=1;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=sashelp.class(obs=12) file=labels align=0 width=15
across=2 between=10 sets=4;
Line 1 name;
Line 2 sex;
Line 3 age;
Line 4 height;
Line 5 weight;
Run;
ALIGN=Specify the number of lines of dummy form units to print.
Options Pagesize=60 Linesize=64 nodate pageno=1;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=sashelp.class(obs=12) file=labels align=2;
Line 1 name;
Line 2 sex;
Line 3 age;
Line 4 height;
Line 5 weight;
Run;
By Statement
Species the variable that the procedure uses to form BY groups. You can specify
more than one variable. If you do not use the NOTSORTED option in the BY
statement, then either the observations in the data set must be sorted by all the
variables that you specify, or they must be indexed appropriately.
Data ds;
Set sashelp.class;
Run;
Proc sort data=ds;
By sex;
Run;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=ds file=labels;
Line 1 name;
Line 2 sex;
Line 3 age;
Line 4 height;
Line 5 weight;
By sex;
Run;
Proc sort data=ds;
By descending age;
Run;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=ds file=labels;
Line 1 name;
Line 2 sex;
Line 3 age;
Line 4 height;
Line 5 weight;
By descending age;
Run;
Notsorted – Without sorting data we can use by variables.
Options Pagesize=60 Linesize=64 nodate;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=sashelp.class file=labels;
Line 1 name;
Line 2 sex;
Line 3 age;
Line 4 height;
Line 5 weight;
By age notsorted;
Run;
Freq Statement
Treats observations as if they appear multiple times in the input data set.
Specifies a numeric variable whose value represents the frequency of each observation. If you use the FREQ statement, then the procedure assumes that each observation in the input data set represents n observations, where n is the value of variable. If n is not an integer, then PROC FORMS truncates it. If n is less than 1 (which includes missing), then the procedure does not use that observation. The sum of the frequency variable represents the total number of observations.
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=sashelp.class(obs=5) file=labels;
Line 1 name;
Line 2 sex;
Line 3 age;
Line 4 height;
Line 5 weight;
By age notsorted;
Freq age;
Run;
Line Statement
Specifies the information to print on one line of the form unit. Use one LINE statement for each line of the form unit.
LINE line-number variable(s) </ option(s)>;
Data ds;
Set sashelp.class;
Run;
Proc sort data=ds;
By sex;
Run;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=ds file=labels;
Line 1 name;
Line 2 sex;
Line 3 age;
Line 4 height;
Line 5 weight;
By sex;
Run;
Options – Line Statement
INDENT=Specify the number of spaces to indent the line within the form unit.
Filename labels
‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=ds file=labels;
Line 1 name/indent=10;
Line 2 sex/indent=10;
Line 3 age;
Line 4 height/indent=2;
Line 5 weight/indent=2;
Run;
LASTNAME
Rotate the words in a character variable that contains a comma around the comma and remove the comma
Data ds;
Infile datalines;
Input idno name:$18. Team: $ strtwght endwght ;
Datalines;
1331 Jason,Schock blue 187 172
1067 Kanoko,Nagasaka green 135 122
1251 Richard,Rose blue 181 166
1192 Charlene,Armstrong yellow 152 139
1352 Bette,Long green 156 137
1262 Yao,Chen blue 196 180
1124 Adrienne,Fink green 156 142
;
Run;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=ds file=labels;
Line 1 idno ;
Line 2 name/lastname;
Line 3 team;
Line 4 strtwght;
Line 5 endwght;
Run;
Data ds;
Infile datalines;
Input idno name&$18. Team $ strtwght endwght ;
Datalines;
1331 Jason,Schock,Long blue 187 172
1067 Kanoko,Nagasaka green 135 122
1251 Richard,Rose blue 181 166
1192 Charlene,Armstrong yellow 152 139
1352 Bette,Long,Schock green 156 137
1262 Yao,Chen,Garg blue 196 180
1124 Adrienne,Fink green 156 142
;
Run;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=ds file=labels;
Line 1 idno/indent=10 ;
Line 2 name/indent=10/lastname;
Line 3 team;
Line 4 strtwght/indent=2;
Line 5 endwght/indent=2;
Run;
PACK
Remove extra blanks from the line so that one blank separates variables.
Data ds;
Infile datalines;
Input idno name:$18. Team: $ strtwght endwght ;
Datalines;
1331 Jason Schock blue 187 172
1067 Kanoko Nagasaka green 135 122
1251 Richard Rose blue 181 166
1192 Charlene Armstrong yellow 152 139
1352 Bette Long green 156 137
1262 Yao Chen blue 196 180
1124 Adrienne Fink green 156 142
;
Run;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=ds file=labels;
Line 1 idno ;
Line 2 name/pack ;
Line 3 team;
Line 4 strtwght;
Line 5 endwght;
Run;
REMOVE
Removes periods that represent missing values from a line that contains no other values.
Data ds;
Infile datalines;
Input idno name&$18. Team: $ strtwght endwght ;
Datalines;
1331 Jason Schock blue 187 172
1067 Kanoko Nagasaka green 135 122
1251 Richard Rose blue 181 166
1192 Charlene Armstrong yellow 152 139
1352 Bette Long green 156 137
1262 Yao Chen blue 196 .
1124 Adrienne Fink green 156 142
;
Run;
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=ds file=labels;
Line 1 idno ;
Line 2 name;
Line 3 team;
Line 4 strtwght;
Line 5 endwght/remove;
Run;
Data list;
Input Name $ 1-19 Street $ 20-39 City $ 40-54 State $ 56-57 Zip $ 59-63;
Datalines;
Ericson, Jane 211 Clancey Court Chapel Hill NC 27514
Dix, Martin L. 4 Shepherd St. Norwich VT 05055
Gabrielli, Theresa 24 Ridgetop Rd. Westboro MA 01581
Clayton, Aria 314 Bridge St. Hanover NH 03755
Archuleta, Ruby Box 108 Milagro NM 87429
Misiewicz, Jeremy 43-C Lakeview Apts. Madison WI 53704
Ahmadi, Hafez 5203 Marston Way Boulder CO 80302
Jacobson, Becky 7 Lincoln St. Tallahassee FL 32312
An, Ing 95 Willow Dr. Charlotte NC 28211
Slater, Emily C. 2009 Cherry St. York PA 17407
;
Run;
Example1:-
Printing a Single Form Unit
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc sort data=list;
by zip;
Run;
Proc forms data=list
file=labels
width=24
across=3
between=4
down=2
skip=2
align=2;
line 1 name / lastname;
line 2 street;
line 3 city state / pack;
line 4 zip / indent=15;
Run;

Example2:-
Printing Two Sets of Mailing Labels
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=list file=labels
ndown=4
cc
width=24
across=2
between=20
down=2
skip=3
align=0
sets=2;
line 1 name;
line 2 street;
line 3 city state zip / pack;
Run;

Example3:-
Writing Multiple Copies of a Label within a Single Set of Labels
Filename labels ‘C:\Documents and Settings\Administrator\Desktop\SAS\sample.rtf’;
Proc forms data=list file=labels
ndown=5
cc
align=0
width=24
across=3
down=2
skip=2
copies=3;
line 1 name / lastname;
line 2 street;
line 3 city state zip / pack;
Where state in(‘ME’, ‘NH’, ‘VT’, ‘MA’, ‘CT’, ‘RI’);
Run;
