| Valid in: | DATA step |
| Category: | File-handling |
| Type: | Executable |
x.
If you use single quotation marks ('') or double quotation marks ("") together (with no space in between them) as the string of text, SAS will output a single quotation mark ( ') or double quotation mark ("), respectively.
put '68656C6C6F'x;
put 132*'_';
If the most recent INPUT statement uses line-pointer controls to read multiple input data records, PUT _INFILE_ writes only the record that the input pointer is positioned on.
input #3 score #1 name $ 6-23; put _infile_;
put @15 name $10.;
a=15; put @a name $10.;
b=5; put @(b*3) name $10.;
put @23 length 4. +5 width 4.;
put @12 name $10. #2 id 3-4;
put name age / id 3-4;
Use OVERPRINT in combination with column pointer and line pointer controls to overprint text.
put @15 'Report Title' overprint
@15 '____________';If you specify FILE PRINT in an interactive SAS session, then the Output window interprets the form-feed control characters as page breaks, and they are removed from the output. The resulting file is a flat file without page break characters. If a file needs to contain the form-feed characters, then the FILE statement should include a physical file location and the PRINT option.
put name 6-15 age 17-19;
put name age;
put name $char10. age 2. +1 date mmddyy10.;
put name= age=;
put name 'on ' date mmddyy8. ' weighs '
startwght +(-1) '.' idno= 40-45;put 'Player:' name1 'Player:' name2 'Player:' name3;
PUT array-name{*}; data club1;
input idno name $ startwght date : date7.;
put name 'on ' date mmddyy8. ' weighs '
startwght +(-1) '.' idno= 32-40;
datalines;
032 David 180 25nov99
049 Amelia 145 25nov99
219 Alan 210 12nov99
;----+----1----+----2----+----3----+----4 David on 11/25/99 weighs 180. idno=1032 Amelia on 11/25/99 weighs 145. idno=1049 Alan on 11/12/99 weighs 210. idno=1219
data carsales;
input item $10. jan : comma5.
feb : comma5. mar : comma5.;
saleqtr1=sum(jan,feb,mar);
/* an expression moves pointer backward */
put '1st qtr sales for ' item
'is ' saleqtr1 : comma6. +(-1) '.';
/* a numeric variable with a negative
value moves pointer backward. */
x=-1;
put '1st qtr sales for ' item
'is ' saleqtr1 : comma5. +x '.';
datalines;
trucks 1,382 2,789 3,556
vans 1,265 2,543 3,987
sedans 2,391 3,011 3,658
;data _null_;
set carsales end=lastrec;
totalsales+saleqtr1;
if lastrec then
put @2 'Total Sales for 1st Qtr'
/ totalsales 10-15;
run;title1;
data statepop;
input state $ cityp90 ncityp90 region @@;
label cityp90= '1990 metropolitan population
(million)'
ncityp90='1990 nonmetropolitan population
(million)'
region= 'Geographic region';
datalines;
ME .443 .785 1 NH .659 .450 1
VT .152 .411 1 MA 5.788 .229 1
RI .938 .065 1 CT 3.148 .140 1
NY 16.515 1.475 1 NJ 7.730 .A 1
PA 10.083 1.799 1 DE .553 .113 2
MD 4.439 .343 2 DC .607 . 2
VA 4.773 1.414 2 WV .748 1.045 2
NC 4.376 2.253 2 SC 2.423 1.064 2
GA 4.352 2.127 2 FL 12.023 .915 2
KY 1.780 1.906 2 TN 3.298 1.579 2
AL 2.710 1.331 2 MS .776 1.798 2
AR 1.040 1.311 2 LA 3.160 1.060 2
OK 1.870 1.276 2 TX 14.166 2.821 2
OH 8.826 2.021 3 IN 3.962 1.582 3
IL 9.574 1.857 3 MI 7.698 1.598 3
WI 3.331 1.561 3 MN 3.011 1.364 3
IA 1.200 1.577 3 MO 3.491 1.626 3
ND .257 .381 3 SD .221 .475 3
NE .787 .791 3 KS 1.333 1.145 3
MT .191 .608 4 ID .296 .711 4
WY .134 .319 4 CO 2.686 .608 4
NM .842 .673 4 AZ 3.106 .559 4
UT 1.336 .387 4 NV 1.014 .183 4
WA 4.036 .830 4 OR 1.985 .858 4
CA 28.799 .961 4 AK .226 .324 4
HI .836 .272 4
;
proc format;
value regfmt 1='Northeast'
2='South'
3='Midwest'
4='West';
run;
data _null_;
set statepop;
by region;
pop90=sum(cityp90,ncityp90);
file print;
put state 1-2 @5 pop90 7.3 ' million';
if first.region then
regioncitypop=0; /* new region */
regioncitypop+cityp90;
if last.region then
do;
put // '1990 US CENSUS for ' region regfmt.
/ 'Total Urban Population: '
regioncitypop' million' _page_;
end;
run;data _null_;
input idno name $ startwght;
file file-specification print;
put name 1-10 @15 startwght 3.;
if startwght > 200 then
put overprint @15 '___';
datalines;
032 David 180
049 Amelia 145
219 Alan 210
;data _null_;
input idno name $ startwght 3.;
put name @;
if startwght ne . then
put @15 startwght;
else put;
datalines;
032 David 180
049 Amelia 145
126 Monica
219 Alan 210
;data _null_; n=5; nvar1=1; var1=7; put @1 'n' nvar1 'n'; run;
/*
* Use #i and @j to position name and weight information into
* four columns in column-major order. That is print down column 1
* first, then print down column 2, etc.
* This example highlights the need to specify # before @ because
* # sets the column pointer to 1.
*/
data _null_;
file print n=ps notitles header=hd;
do i = 1 to 80 by 20;
do j = 1 to ceil(num_students/4);
set sashelp.class nobs=num_students;
put #(j+3) @i name $8. '-' +1 weight 5.1;
end;
end;
stop;
hd:
put @26 'Student Weight in Pounds' / @26 24*'-';
return;
run; Student Weight in Pounds
------------------------
Alfred - 112.5 James - 83.0 Joyce - 50.5 Robert - 128.0
Alice - 84.0 Jane - 84.5 Judy - 90.0 Ronald - 133.0
Barbara - 98.0 Janet - 112.5 Louise - 77.0 Thomas - 85.0
Carol - 102.5 Jeffrey - 84.0 Mary - 112.0 William - 112.0
Henry - 102.5 John - 99.5 Philip - 150.0