sas input v. put functions
TRANSCRIPT
![Page 1: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/1.jpg)
INPUT VSPUT
MSUG | Donna Chan | August 29, 2012
FUNCTIONS
![Page 2: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/2.jpg)
WIIFM BREW SOME SAS-SY
GOODNESS
INPUT+PUT FUNCTIONS
? ()
![Page 3: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/3.jpg)
WIIFM?
![Page 4: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/4.jpg)
123 abc
![Page 5: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/5.jpg)
![Page 6: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/6.jpg)
INPUT+PUT FUNCTIONS ( )
![Page 7: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/7.jpg)
text in
text out
![Page 8: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/8.jpg)
input ;
text in
text out
![Page 9: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/9.jpg)
input ;
put ;
text in
text out
![Page 10: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/10.jpg)
INPUT/PUT statements and functions
are close cousins.
; ()
![Page 11: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/11.jpg)
input()
put()
text in
text out
![Page 12: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/12.jpg)
input()
put()
text in
text out
![Page 13: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/13.jpg)
input()
new = input(old, informat.) ;
abc123
![Page 14: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/14.jpg)
abc123
date_char
‘05282012’
‘06012012’
‘07052012’
new = input(old, informat.) ;
date_num
19141
19145
19179
input()
![Page 15: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/15.jpg)
abc123
date_char
‘05282012’
‘06012012’
‘07052012’
date_num = input(date_char, mmddyy8.) ;
date_num
19141
19145
19179
input()
![Page 16: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/16.jpg)
abc123
date_char
‘05282012’
‘06012012’
‘07052012’
date_num = input(date_char, mmddyy8.) ;
date_num
19141
19145
19179
input()
![Page 17: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/17.jpg)
abc123
date_char
‘05282012’
‘06012012’
‘07052012’
date_num = input(date_char, mmddyy8.) ;
date_num
19141
19145
19179
input()
E
![Page 18: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/18.jpg)
abc123
date_char
‘05282012’
‘06012012’
‘07052012’
date_num = input(date_char, mmddyy8.) ;
date_num
05/28/2012
06/01/2012
07/05/2012
format date_num mmddyy10. ;
input()
C
![Page 19: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/19.jpg)
abc123
date_char
‘05282012’
‘06012012’
‘07052012’
date_num = input(date_char, mmddyy8.) ;
date_num
05/28/2012
06/01/2012
07/05/2012
format date_num mmddyy10. ;
input()
C
I
![Page 20: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/20.jpg)
abc123
some_num
05282012
06012012
07052012
date_num = input(some_num, mmddyy8.) ;
date_num
?
format date_num mmddyy10. ;
input()
![Page 21: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/21.jpg)
abc123
some_num
05282012
06012012
07052012
date_num = input(some_num, mmddyy8.) ;
date_num
.
.
.
format date_num mmddyy10. ;
input()
![Page 22: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/22.jpg)
abc123
some_num
05282012
06012012
07052012
date_num
.
.
.
format date_num mmddyy10. ;
input()
NOTE: Numeric values have been converted to
character values at the places given by:
(Line):(Column).
date_num = input(some_num, mmddyy8.) ;
![Page 23: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/23.jpg)
Old var is always char.
Format dates.
❶ ❷ ❸
input()
If old var is num, SAS returns note.
❹
abc123
new = input(old, informat.) ;
Informat describes how old var appears—in new var type.
![Page 24: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/24.jpg)
input()
put()
text in
text out
![Page 25: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/25.jpg)
new = put(old, format.) ;
put() 123abc
![Page 26: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/26.jpg)
123abc
ID_num
.
1245
35
659845
new = put(old, format.) ;
ID_char
19141
19145
19179
put()
![Page 27: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/27.jpg)
123abc
ID_char = put(ID_num, z6.) ;
ID_num
.
1245
35
659845
put()
ID_char
‘ .’
‘001245’
‘000035’
‘659845’
![Page 28: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/28.jpg)
123abc
ID_char = put(ID_num, z6.) ;
ID_num
.
1245
35
659845
ID_char
‘ .’
‘001245’
‘000035’
‘659845’
put()
E
![Page 29: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/29.jpg)
123abc
else ID_char = put(ID_num, z6.) ;
ID_num
.
1245
35
659845
ID_char
‘’
‘001245’
‘000035’
‘659845’
if ID_num eq . then ID_char = ‘’ ;
put()
C
![Page 30: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/30.jpg)
123abc
ID_char = put(ID_num, z6.) ;
ID_num
.
1245
35
659845
ID_char
‘ .’
‘001245’
‘000035’
‘659845’
I
put()
![Page 31: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/31.jpg)
123abc
ID_char = put(ID_num, $6.) ;
ID_num
.
1245
35
659845
ID_char
? ’
put()
![Page 32: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/32.jpg)
123abc
ID_num
.
1245
35
659845
ID_char
‘ .’
‘ 1245’
‘ 35’
‘659845’
put()
ID_char = put(ID_num, $6.) ;
![Page 33: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/33.jpg)
123abc
ID_num
.
1245
35
659845
ID_char
‘ .’
‘ 1245’
‘ 35’
‘659845’
WARNING: Variable ID_num has already
been defined as numeric.
put()
ID_char = put(ID_num, $6.) ;
![Page 34: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/34.jpg)
put()
New var is always char.
Hardcode missings.
❶ ❷ ❸ Using new var format type will throw warning.
❹
123abc
new = put(old, format.) ;
Format describes what the new var looks like—in old var type.
![Page 35: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/35.jpg)
SAS-SY GOODNESS
BREW SOME
![Page 36: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/36.jpg)
round 1 abc abc ?
![Page 37: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/37.jpg)
round 1
ID_new
‘000451’
‘000934’
‘005660’
‘049712’
‘180456’
‘196245’
abc abc ?
ID_old
‘451’
‘934’
‘5660’
‘49712’
‘180456’
‘196245’
![Page 38: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/38.jpg)
round 1 abc abc
ID_old
‘451’
‘934’
‘5660’
‘49712’
‘180456’
‘196245’
ID_new
‘000451’
‘000934’
‘005660’
‘049712’
‘180456’
‘196245’
ID_new = put(input(ID_old, 6.0), z6.0) ;
![Page 39: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/39.jpg)
ID_new = put(input(ID_old, 6.0), z6.0) ;
ID_old
‘451’
‘934’
‘5660’
‘49712’
‘180456’
‘196245’
char
round 1 abc abc
![Page 40: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/40.jpg)
ID_new = put(input(ID_old, 6.0), z6.0) ;
(inter_num)
451
934
5660
49712
180456
196245
ID_old
‘451’
‘934’
‘5660’
‘49712’
‘180456’
‘196245’
char num
round 1 abc abc
![Page 41: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/41.jpg)
ID_new = put(inter_num, z6.0) ;
(inter_num)
451
934
5660
49712
180456
196245
ID_old
‘451’
‘934’
‘5660’
‘49712’
‘180456’
‘196245’
char num
round 1 abc abc
![Page 42: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/42.jpg)
ID_new = put(inter_num, z6.0) ;
(inter_num)
451
934
5660
49712
180456
196245
ID_old
‘451’
‘934’
‘5660’
‘49712’
‘180456’
‘196245’
char num
round 1 abc abc
![Page 43: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/43.jpg)
ID_new
000451
000934
005660
049712
180456
196245
(inter_num)
451
934
5660
49712
180456
196245
ID_old
‘451’
‘934’
‘5660’
‘49712’
‘180456’
‘196245’
char num char
round 1 abc abc
ID_new = put(inter_num, z6.0) ;
![Page 44: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/44.jpg)
new = put(input(old, 6.0), z6.0) ;
round 1
Nest functions when going from char to char.
Don’t be afraid; break it down step-by-step.
❶ ❷
abc abc
![Page 45: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/45.jpg)
round 2 custom informat: abc 123 ?
![Page 46: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/46.jpg)
gpa_char
‘A-’
‘B+’
‘C’
‘B-’
‘B’
‘D’
gpa_num
‘000451’
‘000934’
‘005660’
‘049712’
‘180456’
‘196245’
round 2 custom informat: abc 123 ?
![Page 47: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/47.jpg)
if gpa_char in ('A+' 'A') then gpa_num = 4.0 ;
else if gpa_char = 'A-' then gpa_num = 3.7 ;
else if gpa_char = 'B+' then gpa_num = 3.3 ;
else if gpa_char = 'B' then gpa_num = 3.0 ;
else if gpa_char = 'B-' then gpa_num = 2.7 ;
else if gpa_char = 'C+' then gpa_num = 2.3 ;
else if gpa_char = 'C' then gpa_num = 2.0 ;
else if gpa_char = 'D' then gpa_num = 1.0 ;
else if gpa_char = 'F' then gpa_num = 0 ;
else gpa_char = '' ;
round 2 custom informat: abc 123
![Page 48: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/48.jpg)
proc format;
invalue gpafmt ‘A+’ = 4.0
‘A’ = 4.0
‘A-’ = 3.7
‘B+’ = 3.3
‘B’ = 3.0
‘B-’ = 2.7
‘C+’ = 2.3
‘C’ = 2.0
‘D’ = 1.0
‘F’ = 0 ;
run;
gpa_num = input(gpa_char, gpafmt.);
round 2 custom informat: abc 123
![Page 49: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/49.jpg)
round 2
gpa_char
‘A-’
‘B+’
‘C’
‘B-’
‘B’
‘D’
gpa_num
3.7
3.3
2.0
2.7
3.0
1.0
custom informat: abc 123
![Page 50: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/50.jpg)
gpa_num = input(gpa_char, informat.);
round 2
gpa_char
‘A-’
‘B+’
‘C’
‘B-’
‘B’
‘D’
gpa_num
3.7
3.3
2.0
2.7
3.0
1.0
custom informat: abc 123
![Page 51: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/51.jpg)
round 2
gpa_char
‘A-’
‘B+’
‘C’
‘B-’
‘B’
‘D’
gpa_num
3.7
3.3
2.0
2.7
3.0
1.0
gpa_num = input(gpa_char, gpafmt.);
custom informat: abc 123
proc format;
invalue gpafmt ‘A+’ = 4.0
‘A’ = 4.0
‘A-’ = 3.7
‘B+’ = 3.3
‘B’ = 3.0
‘B-’ = 2.7
‘C+’ = 2.3
‘C’ = 2.0
‘D’ = 1.0
‘F’ = 0 ;
run;
![Page 52: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/52.jpg)
new = input(old, custominfmt.) ;
round 2 custom informat: abc 123
Convert from char to num not just in type but also content.
Powerful for simplifying code.
❶ ❷
![Page 53: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/53.jpg)
bonus round custom format: 123 abc ?
gpa_avg
3.50000
2.66667
2.31540
1.34500
3.95000
2.45150
...
gpa_letter
3.7
3.3
2.0
2.7
3.0
1.0
![Page 54: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/54.jpg)
if 0 =< gpa_avg < 0.7 then gpa_letter = ‘F’ ;
else if 0.7 =< gpa_avg < 1.7 then gpa_letter = ‘D’ ;
else if 1.7 =< gpa_avg < 2.7 then gpa_letter = ‘C’ ;
else if 2.7 =< gpa_avg < 3.7 then gpa_letter = ‘B’ ;
else if 3.7 =< gpa_avg < 4.0 then gpa_letter = ‘A’ ;
else if gpa_avg = . then gpa_letter = ‘’ ;
bonus round custom format: 123 abc ?
![Page 55: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/55.jpg)
proc format ;
value gpafmt 0 -< 0.7 = 'F'
0.7 -< 1.7 = 'D'
1.7 -< 2.7 = 'C'
2.7 -< 3.7 = 'B'
3.7 - 4.0 = 'A' ;
run ;
gpa_letter = put(gpa_avg, gpafmt.);
bonus round custom format: 123 abc
![Page 56: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/56.jpg)
bonus round
gpa_avg
3.50000
2.66667
2.31540
1.34500
3.95000
2.45150
...
gpa_letter
3.7
3.3
2.0
2.7
3.0
1.0
custom format: 123 abc
![Page 57: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/57.jpg)
bonus round
gpa_letter = put(gpa_avg, format.);
custom format: 123 abc
gpa_avg
3.50000
2.66667
2.31540
1.34500
3.95000
2.45150
...
gpa_letter
3.7
3.3
2.0
2.7
3.0
1.0
![Page 58: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/58.jpg)
bonus round
gpa_letter = put(gpa_avg, format.);
custom format: 123 abc
gpa_avg
3.50000
2.66667
2.31540
1.34500
3.95000
2.45150
...
gpa_letter
3.7
3.3
2.0
2.7
3.0
1.0
proc format ;
value gpafmt 0 -< 0.7 = 'F'
0.7 -< 1.7 = 'D'
1.7 -< 2.7 = 'C'
2.7 -< 3.7 = 'B'
3.7 - 4.0 = 'A' ;
run ;
![Page 59: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/59.jpg)
bonus round
gpa_letter = put(gpa_avg, gpafmt.);
custom format: 123 abc
gpa_avg
3.50000
2.66667
2.31540
1.34500
3.95000
2.45150
...
gpa_letter
3.7
3.3
2.0
2.7
3.0
1.0
proc format ;
value gpafmt 0 -< 0.7 = 'F'
0.7 -< 1.7 = 'D'
1.7 -< 2.7 = 'C'
2.7 -< 3.7 = 'B'
3.7 - 4.0 = 'A' ;
run ;
![Page 60: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/60.jpg)
bonus round
gpa_avg
3.50000
2.66667
2.31540
1.34500
3.95000
2.45150
...
gpa_letter
‘B’
‘C’
‘C’
‘D’
‘A’
‘C’
...
gpa_letter = put(gpa_avg, gpafmt.);
custom format: 123 abc
proc format ;
value gpafmt 0 -< 0.7 = 'F'
0.7 -< 1.7 = 'D'
1.7 -< 2.7 = 'C'
2.7 -< 3.7 = 'B'
3.7 - 4.0 = 'A' ;
run ;
![Page 61: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/61.jpg)
new = put(old, customfmt.) ;
Convert from num to char not just in type but also content.
Powerful for clarifying output.
❶ ❷
bonus round custom format: 123 abc
![Page 62: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/62.jpg)
![Page 63: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/63.jpg)
FOLD
TACK ENJOY
![Page 64: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/64.jpg)
CONTACT
REFERENCES
Donna Chan
ext 8883
room 1864
1 – An Animated Guide: Using the Put and Input Functions | 2008
by Russ Lavery & Alejandro Jaramillo
2 – Using PROC FORMAT to Create Dynamic Lookups | 2012
by Jed Teres
3 – Five Things Every Presenter Should Know About People | 2012
by Brain Pickings
![Page 65: SAS Input v. Put Functions](https://reader036.vdocument.in/reader036/viewer/2022082216/55c4cc55bb61ebed3f8b4819/html5/thumbnails/65.jpg)