Hello team,
I have the coes as below:
LibName MyLibName 'Path';
Infile "Path";
Input Id$ sex$ DOB pdX Dx_3 Dx_4;
Informat DOB Date9.;
I know SAS sees the date as number of days away far from January 1st, 1960.
The file from which I have imported data into SAS has this format for DOB: mm-dd-yy.
We put informat function in declaration part of the code, which is to say in input statement. What is the role of it? Does informat change mm-dd-yy to a number so SAS can understand DOB?
Please advise me.
Blue Blue Sky
"When SAS reads the data in PDV, what does informat play in this scenario?"
Some docu here - may-be too much for you right now.
When SAS reads an external file then:
1. Reads a record into the input buffer
2. Reads the data in the input buffer into the PDV
The input buffer just got one record from your external data "as is" loaded into memory.
The PDV got one row/obs of your data in SAS variables.
Options in the infile statement together with informats provide to SAS the instructions how to map (and convert) the data in the input buffer into SAS variables.
Let's say you've got in your external data a string like 05May2021
In the input buffer this is still 05May2021
In your input statement you've got now something like: mydate date9.
The date9. informat provides to SAS the instruction how to read the string 05May2021 into SAS variable mydate. Using this informat SAS will convert the string 05May2021 into a SAS Date value which is the count of days since 1/1/1960 (=22405).
A format instructs SAS how to print a value. Taking above example if you just print the values stored in variable mydate without a format then you will get 22405 - which is not human readable.
A format of date9. (same name like the informat but you could also use some different format like ddmmyy10.) applied to variable mydate will print the same internal value of 22405 as 05May2021.
I hope above was helpful and didn't just confuse you.
Here is a sample program you can use to answer your own question:
data _null_;
input date ;
informat date mmddyy10.;
put 'Using no assigned format: ' @28 date=;
put 'Using date9 format: ' @28 date=date9.;
put 'Using mmddyy10. format: ' @28 date=mmddyy10.;
datalines;
04/24/2021
run;
which generates on the log:
Using no assigned format: date=22394
Using date9 format: date=24APR2021
Using mmddyy10. format: date=04/24/2021
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
You can see, by using the informat mmddyy10., SAS converted the external string "04/24/2021" to an internal value (22394), which appears on the log according to the assigned format (not informat).used in the PUT statement.
@GN0001 wrote:
Hello Mkeintz,
What is the role informat here? Does it convert a date such as 04-22-2021 to number so SAS can read the date variable? If we remove informat statement, sas is not able to read the date. The log shows ..
I found this: SAS Informat Statement SAS Informat is an instruction that SAS used to read data values into a variable.
I know format displays date in a way that we can understand.
Regards,
Blue Sky
Your file does not have a date, it has a string of text characters. The role of the INFORMAT statement is to attach an informat specification to a variable. So that when the INPUT statement does not explicitly state what informat to use for that variable the INPUT statement will use the informat that is attached to the variable.
Remember: Informats convert text to values. Formats convert values to text.
First of all, you have an INFORMAT statement, not a function (there is no INFORMAT function).
You need to use an informat that matches the format of your date.
DATE9 expects ddmmmyyyy, where the month is written as a 3-character abbreviation. From your description, I take it that you should use the MMDDYY8. informat.
Which idiot sends you dates with 2-digit years? With 4-digit years, use MMDDYY10.
@GN0001 wrote:
When SAS reads the data in PDV, what does informat play in this scenario?
The informat is a template that tells SAS how to convert a part of the input stream to a data value for use in the data step. Some are very simple (e.g. $10., which reads the next 10 characters), others quite complex (like the date, time and datetime informats). $10. will read anything, while MMDDYY10. expects a valid date (although it tolerates a wide range of separators and dates shorter than 10 characters).
data check;
input date mmddyy10.;
format date yymmdd10.;
datalines;
02-03-2021
02/03/2021
02 03 2021
02.03.2021
02_03_2021
02:03:2021
2/3/2021
02032021
232021
;
(only the last one will be rejected)
If your instructor insists on calling INFORMAT a function, direct her/him here, and ask where the function can be found 😉
"When SAS reads the data in PDV, what does informat play in this scenario?"
Some docu here - may-be too much for you right now.
When SAS reads an external file then:
1. Reads a record into the input buffer
2. Reads the data in the input buffer into the PDV
The input buffer just got one record from your external data "as is" loaded into memory.
The PDV got one row/obs of your data in SAS variables.
Options in the infile statement together with informats provide to SAS the instructions how to map (and convert) the data in the input buffer into SAS variables.
Let's say you've got in your external data a string like 05May2021
In the input buffer this is still 05May2021
In your input statement you've got now something like: mydate date9.
The date9. informat provides to SAS the instruction how to read the string 05May2021 into SAS variable mydate. Using this informat SAS will convert the string 05May2021 into a SAS Date value which is the count of days since 1/1/1960 (=22405).
A format instructs SAS how to print a value. Taking above example if you just print the values stored in variable mydate without a format then you will get 22405 - which is not human readable.
A format of date9. (same name like the informat but you could also use some different format like ddmmyy10.) applied to variable mydate will print the same internal value of 22405 as 05May2021.
I hope above was helpful and didn't just confuse you.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.