error · ta à numeric ulations. now that i know what format i want, how do make it happen?...
TRANSCRIPT
![Page 1: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/1.jpg)
![Page 2: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/2.jpg)
![Page 3: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/3.jpg)
ERROR:
ERROR:
ERROR:
ERROR:
ERROR:
![Page 4: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/4.jpg)
Formatting Variables: Back and forth between character and numeric Back and forth between character and numeric
Formatting Variables: Back and forth between character and numeric Back and forth between character and numeric
![Page 5: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/5.jpg)
Why should you care? DATA name1; SET name; if var = ‘Three’ then delete; if var = ‘3’ then delete; if var = ‘3’ then delete; if var = 3 then delete;
RUN;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
Why should you care?
if var = ‘Three’ then delete; if var = ‘3’ then delete; if var = ‘3’ then delete; if var = 3 then delete;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
![Page 6: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/6.jpg)
Why should you care? DATA name1; SET name; if var = ‘Three’ then delete; if var = ‘3’ then delete; if var = ‘3’ then delete; if var = 3 then delete;
RUN;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
Why should you care?
if var = ‘Three’ then delete;; if var = ‘3’ then delete; if var = ‘3’ then delete; if var = 3 then delete;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
![Page 7: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/7.jpg)
Why should you care? DATA name1; SET name; if var = ‘Three’ then delete; if var = ‘3’ then delete; if var = ‘3’ then delete; if var = 3 then delete;
RUN;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
Why should you care?
if var = ‘Three’ then delete; if var = ‘3’ then delete; if var = ‘3’ then delete; if var = 3 then delete;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
![Page 8: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/8.jpg)
Why should you care? DATA name1; SET name; if var = ‘Three’ then delete; if var = ‘3’ then delete; if var = ‘3’ then delete; if var = 3 then delete;
RUN;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
Why should you care?
if var = ‘Three’ then delete; if var = ‘3’ then delete; if var = ‘3’ then delete; if var = 3 then delete;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
![Page 9: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/9.jpg)
Why should you care? DATA name1; SET name; if var = ‘Three’ then delete; if var = ‘3’ then delete; if var = ‘3’ then delete; if var = 3 then delete;
RUN;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
OK
Why should you care?
if var = ‘Three’ then delete; if var = ‘3’ then delete; if var = ‘3’ then delete; if var = 3 then delete;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
OK
![Page 10: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/10.jpg)
Why should you care? DATA name1; SET name; if var = ‘Three’ if var = ‘3’ then delete; if var = ‘3’ then delete; if var = 3 then delete;
RUN;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
OK
Why should you care?
’ then delete; then delete; then delete;
if var = 3 then delete;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
OK
![Page 11: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/11.jpg)
PROBLEM: Identify the same variable as character and numeric
SAS attempts to make them comparable § Character ßà Numeric
“Implicit” coding “Implicit” coding
Should avoid § SAS is making the decisions § Opportunity to introduce errors § FRUSTRATION!
PROBLEM: Identify the same variable as character and
SAS attempts to make them comparable
SAS is making the decisions – not you Opportunity to introduce errors
![Page 12: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/12.jpg)
Know the current format of your data.
PROC CONTENTS; RUN; PROC CONTENTS; RUN;
Know the current format of your data.
PROC CONTENTS; RUN; PROC CONTENTS; RUN;
![Page 13: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/13.jpg)
![Page 14: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/14.jpg)
SAS Enterprise Guide SAS Enterprise Guide
![Page 15: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/15.jpg)
CHAR CHAR NUM
Regular SAS CHAR CHAR
![Page 16: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/16.jpg)
How do I decide what format my variable should be?
How do I decide what format my variable should be?
![Page 17: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/17.jpg)
Selecting the best format
Obvious choices § if a variable contains non-numeric information § If a variable contains numeric data
Not so obvious choices Not so obvious choices § Integer data that won’t be used in any calculations § ID Number = 1757638
§ Nominal variables § Sex: 1 = Male, 2 = Female
Use numeric variables whenever possible § Eliminates leading and trailing blanks
Selecting the best format
numeric information à character If a variable contains numeric data à numeric
Integer data that won’t be used in any calculations
Use numeric variables whenever possible Eliminates leading and trailing blanks
![Page 18: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/18.jpg)
Now that I know what format I want, how do make it happen? want, how do make it happen? Now that I know what format I want, how do make it happen? want, how do make it happen?
![Page 19: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/19.jpg)
INFORMATS
FORMATS FORMATS
INPUT & PUT statements
INFORMATS
FORMATS FORMATS
INPUT & PUT statements
![Page 20: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/20.jpg)
Non-SAS input file
SAS dataset
INFORMAT
Tells SAS how to read data from external files into SAS variables
input file dataset
INPUT statement PUT statement
SAS dataset
Output
FORMAT
Instructions for outputting data
Changes how the variable is presented but does not change the variable itself
dataset
INPUT statement PUT statement
![Page 21: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/21.jpg)
INFORMAT DATA name; Infile ‘C:/My Files/Jacq’;
informat VAR1 $8.; informat VAR2 4.1; informat VAR2 4.1; input VAR1 $
VAR2 ;
RUN;
Infile ‘C:/My Files/Jacq’; informat VAR1 $8.; informat VAR2 4.1; informat VAR2 4.1;
![Page 22: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/22.jpg)
Numeric examples § 4.1 § COMMA10. § HEX4.
Character examples Character examples § $CHAR10. § $10. § $HEX4.
![Page 23: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/23.jpg)
FORMAT PROC FORMAT; value gender 1
2 RUN; RUN;
PROC PRINT; VAR var_name; FORMAT var_name gender. RUN;
= ‘Male’ = ‘Female’;
gender.;
![Page 24: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/24.jpg)
FORMAT PROC FORMAT; value gender 1 = ‘Male’
2 = ‘Female’; RUN; RUN;
PROC PRINT; VAR var_name; FORMAT var_name gender. RUN;
1 = ‘Male’ 2 = ‘Female’;
gender.;
![Page 25: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/25.jpg)
FORMAT PROC FORMAT; value $gender ‘M’ = ‘Male’
‘F’ = ‘Female’; RUN; RUN;
PROC PRINT; VAR var_name; FORMAT var_name $gender.; RUN;
‘M’ = ‘Male’ ‘F’ = ‘Female’;
FORMAT var_name $gender.;
![Page 26: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/26.jpg)
FORMAT PROC FORMAT; value $gender ‘M’ = ‘Male’
‘F’ = ‘Female’; RUN; RUN;
PROC PRINT; VAR var_name; FORMAT var_name $ RUN;
‘M’ = ‘Male’ ‘F’ = ‘Female’;
$gender.;
![Page 27: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/27.jpg)
INPUT & PUT Statements INPUT - converts character to numeric
PUT - converts numeric to character
Not possible to directly change the type of variable § Must create new variable § Rename § Drop
INPUT & PUT Statements converts character to numeric
converts numeric to character
Not possible to directly change the type of
Must create new variable
![Page 28: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/28.jpg)
DATA data1; SET data;
/*Character to numeric */ new_num=INPUT(char_var,$4);
/* Numeric to character */ new_char=PUT(num_var,4.0);
RUN;
Character to numeric */ new_num=INPUT(char_var,$4);
/* Numeric to character */ new_char=PUT(num_var,4.0);
![Page 29: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/29.jpg)
In sum…. In sum….
![Page 30: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/30.jpg)
What format should you use when the choice is not obvious?
NUMERIC NUMERIC
Why?
Don’t have to worry about leading or trailing blanks
What format should you use when the choice is
Don’t have to worry about leading or trailing
![Page 31: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/31.jpg)
Know the current format of your data.
1. PROC CONTENTS 2. Enterprise Guide SAS 2. Enterprise Guide SAS
- Numeric - blue circles - Character - red triangles
3. REGULAR SAS - Numeric – right justified - Character – left justified
Know the current format of your data.
Enterprise Guide SAS Enterprise Guide SAS blue circles
red triangles
right justified left justified
![Page 32: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/32.jpg)
Non-SAS input file
SAS dataset
INFORMAT
? ?
input file dataset
INPUT statement PUT statement
? SAS
dataset Output
FORMAT
? ?
dataset
INPUT statement PUT statement
?
![Page 33: ERROR · ta à numeric ulations. Now that I know what format I want, how do make it happen? INFORMATS FORMATS ... Know the current format of your data. 1. PROC CONTENTS 2. Enterprise](https://reader030.vdocuments.mx/reader030/viewer/2022041122/5d1e8e7e88c9936f5d8ba5b5/html5/thumbnails/33.jpg)
NOTE: The data set COPD.MASTER has
14,295 observations and 23 variables
NOTE: The data set COPD.MASTER has
14,295 observations and 23 variables