Study guide
5.5 Explicit & Implicit Data Type Conversions (INPUT & PUT)
SAS Certified Specialist: Base Programming Using SAS 9.4 A00-231
Track your progress as you read
Finished sections get a check mark.
1 Chapter 1: SAS Base Programming Exam Overview
1.1 A00-231 Exam Format, Scoring & Test-Day Logistics 1.2 Official Content Areas, Weights & Study Plan
2 Chapter 2: Accessing & Creating SAS Data Structures
2.1 SAS Environment, Syntax Rules, & Data Step Basics 2.2 SAS Data Libraries & the LIBNAME Statement 2.3 Investigating Libraries with PROC CONTENTS & PROC DATASETS 2.4 Importing Delimited & Excel Data with PROC IMPORT 2.5 Raw Data Ingestion with INFILE and INPUT Statements
3 Chapter 3: Managing & Combining SAS Data Sets
3.1 Reading SAS Data Sets with the SET Statement 3.2 Combining Data Sets: Concatenating & Interleaving 3.3 Match-Merging with BY Statements & FIRST./LAST. Processing 3.4 Controlling Data Output & Variable Selection (KEEP, DROP, RENAME, OBS=)
4 Chapter 4: Data Transformation & Conditional Logic
4.1 Creating & Modifying Variables with Assignment Statements 4.2 Modifying Variable Attributes with LENGTH, LABEL, FORMAT & RENAME= 4.3 Conditional Processing: IF-THEN/ELSE Statements & WHERE Subsetting 4.4 Accumulating Totals & Subtotals (RETAIN & Sum Statement) 4.5 Processing Data Iteratively with DO Loops
5 Chapter 5: SAS Functions & Data Type Conversions
5.1 Character Functions for String Manipulation 5.2 Numeric & Mathematical Functions 5.3 Working with SAS Dates, Times, & Intervals 5.4 Reading & Displaying Dates with Informats and Formats 5.5 Explicit & Implicit Data Type Conversions (INPUT & PUT)
6 Chapter 6: Restructuring Data & Program Maintenance
6.1 SAS Array Processing for Multi-Variable Transformations 6.2 Sorting Data Sets with PROC SORT 6.3 Restructuring Data Sets with PROC TRANSPOSE 6.4 Creating & Applying Custom Formats with PROC FORMAT 6.5 Simplifying Programs with Macro Variables (%LET)
7 Chapter 7: Error Handling & Debugging SAS Programs
7.1 SAS Log Analysis & Diagnostic Messages 7.2 Syntax vs. Logic Errors & Phasing 7.3 Debugging Techniques with _ERROR_, _N_, & PUT Statements 7.4 Identifying Logic Errors with the PUTLOG Statement 7.5 Handling Missing Values & Preventing Calculation Propagations
8 Chapter 8: Summary & Detail Data Reporting
8.1 Detail Reporting with PROC PRINT 8.2 Descriptive Statistics with PROC MEANS & PROC SUMMARY 8.3 Frequency & Categorical Analysis with PROC FREQ 8.4 Screening Extreme & Missing Values with PROC UNIVARIATE 8.5 Custom Tabular Reports with PROC REPORT & PROC TABULATE
9 Chapter 9: ODS Output Delivery & Data Export
9.1 Output Delivery System (ODS) Architecture Basics 9.2 Generating PDF, HTML, & RTF Output Destinations 9.3 Exporting Reports to Excel with ODS EXCEL & XLSX 9.4 Generating CSV, PowerPoint & Other ODS Destinations 9.5 Customizing ODS Titles, Footnotes, & Global Options 9.6 Exporting SAS Data Sets with PROC EXPORT & the XLSX Engine
5.5 Explicit & Implicit Data Type Conversions (INPUT & PUT)
Key Takeaways Explain This Topic AI
The INPUT function converts character values to numeric (or character) values using an INFORMAT, always returning a data type matching the informat.
The PUT function converts numeric (or character) values to character values using a FORMAT, always returning a character string.
Assigning a numeric result to an existing character variable is not an error: SAS converts it back to character with the BESTw. format (w = the variable's length) and writes a 'Numeric values have been converted to character values' note.
Implicit character-to-numeric conversion occurs when character variables are used in arithmetic operations, producing a note in the SAS log.
If implicit character-to-numeric conversion fails due to invalid characters, SAS assigns a missing value (.), sets ERROR = 1, and prints an invalid data note to the log.
Last updated: August 2026
5.5 Explicit & Implicit Data Type Conversions (INPUT & PUT)
SAS supports exactly two data types: numeric and character . Frequently, incoming datasets contain numbers stored in character variables (e.g., "$1,250.50" or "20260101" ) or numeric values that must be formatted as character strings for concatenation or reporting. Converting data between character and numeric types—both explicitly and implicitly—is one of the most frequently examined domains on the SAS Certified Specialist Base Programming exam.
1. Explicit Character-to-Numeric Conversion: The INPUT Function
The INPUT function converts character values to numeric or character values based on a specified INFORMAT . Syntax: target_variable = INPUT ( source_variable , informat. ) ; \text{Syntax: } \text{target\_variable} = \text{INPUT}(\text{source\_variable}, \text{informat.}); Syntax: target_variable = INPUT ( source_variable , informat. ) ;
source_variable : The character variable or string to be converted.
informat. : The SAS informat that instructs SAS how to read and interpret the source string. data work.convert_char_to_num;
- char_price = "$1,250.75";
- char_date = "10/31/2026";
- /* Convert formatted character currency to numeric */
- num_price = input(char_price, dollar10.2);
- /* Convert character date string to SAS date integer */
- num_date = input(char_date, mmddyy10.);
- format num_date date9. num_price dollar10.2;
- run;
Important
Memory Rule: The INPUT function requires an INFORMAT (with a dot). The data type of target_variable is determined by the informat used. If the informat is numeric (such as 8. or COMMA9. ), target_variable becomes numeric.
2. Explicit Numeric-to-Character Conversion: The PUT Function
The PUT function converts numeric or character values into character values formatted according to a specified FORMAT . Syntax: target_variable = PUT ( source_variable , format. ) ; \text{Syntax: } \text{target\_variable} = \text{PUT}(\text{source\_variable}, \text{format.}); Syntax: target_variable = PUT ( source_variable , format. ) ;
source_variable : The numeric variable or expression to be converted.
format. : The SAS format that instructs SAS how to write out the character string. data work.convert_num_to_char;
- num_code = 4096;
- sas_date = 24107; /* Represents 01JAN2026 */
- /* Convert numeric integer to 6-character string padded with leading zeros */
- char_code = put(num_code, z6.); /* Result: '004096' */
- /* Convert SAS date integer to character string formatted as YYYY-MM-DD */
- char_date = put(sas_date, yymmdd10.); /* Result: '2026-01-01' */
- run;
Important
The PUT function always returns a character string. Therefore, target_variable is always created as a character variable.
3. Variable Re-assignment Rules & Type Conflicts
In a SAS DATA step, a variable's data type is established upon its first reference during compilation and cannot be changed during execution. A widespread misconception is that re-assigning a converted value to the same variable name raises an error. It does not — SAS silently converts the value back , which is more dangerous than an error because the program keeps running with corrupted data. /* WRONG - but NOT an error. SAS silently converts the number back to text! */
- data work.error_example;
- salary = "50000"; /* SALARY is CHARACTER, length 5 */
- salary = input(salary, 8.); /* INPUT returns numeric 50000 ... */
- run; /* ... then SAS converts it back to */
- /* character using BEST5. */
SAS Log Output: NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
SALARY remains a character variable. Per the SAS 9.4 language reference, when a numeric result is assigned to a character variable SAS applies the BESTw. format, where w is the length of the character variable (maximum 32). Because SALARY is 5 bytes, BEST5. reproduces '50000' . Had SALARY been declared $3 , the number would not fit and SAS would fill the variable with asterisks ( '***' ) and note invalid character data.
Correct Pattern for In-Place Conversion:
To replace a character variable with a numeric variable of the same name, use dataset options ( RENAME= and DROP= ) during compilation: data work.correct_reassign (drop=char_salary);
- set work.raw_data (rename=(salary=char_salary));
- salary = input(char_salary, 8.); /* New numeric variable SALARY */
- run;
- 4. Implicit (Automatic) Data Type Conversions
When a variable of one data type is used in a context that requires the other data type, SAS attempts an implicit type conversion automatically.
Character-to-Numeric Implicit Conversion
Implicit character-to-numeric conversion occurs when a character variable is used in a numeric context, such as:
- Arithmetic operators ( + , - , * , / )
- Logical comparison with numeric constants
- Assignment to a numeric variable data work.implicit_num;
- char_val = "100";
- total = char_val + 50; /* Implicitly converts char_val to numeric 100 */
- run;
SAS Log Output: NOTE: Character values have been converted to numeric values at the places given by: Line 3 Column 13.
What Happens If Implicit Conversion Fails?
If char_val contains non-numeric characters (e.g., "100ABC" or "$50" ), SAS cannot perform the implicit conversion:
SAS sets the target variable to missing ( . ).
SAS sets the automatic variable _ERROR_ = 1 .
SAS writes a note to the log: NOTE: Invalid numeric data, '100ABC' , at line 3 column 13.
Numeric-to-Character Implicit Conversion
Implicit numeric-to-character conversion occurs when a numeric variable appears in a character context, such as:
- Character functions (e.g., SUBSTR , SCAN , CATX )
- Concatenation operator ( || )
- Assignment to a character variable
When converting numeric to character implicitly, SAS applies the BEST12. format, right-aligning the result in a 12-byte string. data work.implicit_char;
- num_id = 789;
- /* Implicitly converts num_id using BEST12. format */
- combo = "ID-" || num_id;
- run;
Caution
Because SAS uses BEST12. for implicit numeric-to-character conversion, the resulting string contains leading blanks (9 spaces followed by 789 ). Thus, combo becomes "ID- 789" ! Perform an explicit conversion and strip the padding instead: combo = "ID-" || strip(put(num_id, best12.)); or simply combo = cats("ID-", num_id); . Note that strip() must wrap the whole PUT() call — put(num_id, strip(best.)) is invalid syntax, because the second argument of PUT must be a format, never a function call.
5. Summary Matrix: INPUT vs. PUT
- Feature INPUT Function PUT Function
- Primary Purpose Converts Character → \rightarrow → Numeric Converts Numeric → \rightarrow → Character
- Argument Required INFORMAT (e.g., comma9. , mmddyy10. ) FORMAT (e.g., z5. , dollar10.2 )
- Return Type Defined by informat (usually numeric) Always CHARACTER
- Best Used For Reading raw strings into usable numbers Formatting values for output/strings
- Handling Blanks Reads formatted input strings Right-aligns numbers via format