input data is 30JAN2019
Date9. is informat
format is MMDDYY10.
01/30/2019 is supposed to be expected, but output is 01/30/2020 if I set yearcutoff to 2000
If I set yearcutoff to 1900 then output is 01/30/1920
But only 01/30/2019 is correct.
Tried multiple times but I still cannot work it out. Thanks a lot !!!
There's the problem. You are reading in the two blanks in columns 38 and 39, as part of the 9 characters that make up DOB. Switch from:
DOB date9.
to either of these:
@40 DOB date9.
or
DOB : date9.
Thank you so much
But I'm 100% sure I used date9. informat
It's either a truncated source string (only the first 7 characters) or the date7. informat. I can't think of any other reason and it's 99.99999% not a SAS bug.
options yearcutoff=2000;
data sample;
format myDateInfmt9 myDateInfmt7 myDateString7 mmddyy10.;
myDateInfmt9=input('30JAN2019',date9.);
myDateInfmt7=input('30JAN2019',date7.);
myDateString7=input('30JAN20',date9.);
output;
stop;
run;
proc print data=sample;
run;
Thanks a lot for the examples you provided and they are really perfect ones. I'll keep it for my future use.
My code is:
options yearcutoff=2000;
data test;
input idno Name $16. color $7. hegt 30-32 wegt 35-37 DOB Date9. salary dollar10.2 ;
format DOB MMDDYY10.;
cards;
023 David Shaw red 189 165 30JAN2019 $68,000
049 Amelia Serrano yellow 189 165 28FEB2018 $89,000.77
;
run;
Welcome to the SAS forums.
> input data is 30JAN2019
In a text file? in a data set? Something else?
If a text file, provide the code that reads the text file.
If not, provide the proc contents output of the source table.
Thank you so much. What will the output you get from the following code?
options yearcutoff=2000;
data test;
input idno Name $16. color $7. hegt 30-32 wegt 35-37 DOB Date9. salary dollar10.2 ;
format DOB MMDDYY10.;
cards;
023 David Shaw red 189 165 30JAN2019 $68,000
049 Amelia Serrano yellow 189 165 28FEB2018 $89,000.77
;
run;
There's the problem. You are reading in the two blanks in columns 38 and 39, as part of the 9 characters that make up DOB. Switch from:
DOB date9.
to either of these:
@40 DOB date9.
or
DOB : date9.
Thanks a million!!
What's the meaning by adding a comma in the middle of DOB and Date9. ?
sorry, what's the meaning by adding a colon between DOB and Date9. ?
The colon means:
Scan through the line of data until you find a nonblank. Then apply the DATE9 informat.
Lots of people use that approach. I prefer the other one (@40 dob date9.) just in case the DOB is actually missing on that line of data.
That is the case...
I add @52 in front of salary and 68,000 truncated to 680. Is that normal?
options yearcutoff=2000;
data test;
input idno Name $16. color $7. hegt 30-32 wegt 35-37 DOB: Date9. @52 salary dollar10.2 ;
format DOB MMDDYY10.;
cards;
023 David Shaw red 189 165 30JAN2019 $68,000
049 Amelia Serrano yellow 189 165 28FEB2018 $89,000.77
;
run;
@runrunbunny wrote:
That is the case...
I add @52 in front of salary and 68,000 truncated to 680. Is that normal?
options yearcutoff=2000;
data test;
input idno Name $16. color $7. hegt 30-32 wegt 35-37 DOB: Date9. @52 salary dollar10.2 ;
format DOB MMDDYY10.;
cards;
023 David Shaw red 189 165 30JAN2019 $68,000
049 Amelia Serrano yellow 189 165 28FEB2018 $89,000.77
;
run;
Don't place a decimal indicator with the informat when used this way. It does an implied decimal, a feature created from the days of punch cards. Just indicate the expected width of the longest value, including the decimal portion PLUS the actual decimal point, such as Dollar10.
Example of data that I intend the last two digits to be decimal values
data example; input x 5.2; datalines; 12345 6789 ; run;
Impressive example and now I get it.
Thank you so much !!!
Note that in LIST mode input (which is what the colon modify triggers) you do not need use DATE9 (instead of DATE7 or just DATE) since the width on the informat is ignored. Instead SAS will use the length of the next word in the input stream.
input dob :date. ;
...
informat dob date.;
input dob;
Some people like to include widths when reading character variables because they have not previously defined the variables before the INPUT statement. So in that case the data step compiler will use the width of the informat specification to guess how long of a character variable to create. That doesn't really apply to numeric variables like DATE since those always use the full 8 bytes it takes to represent a floating point number while the step is running. If you want to store fewer bytes for your numeric variable in the output dataset you have to use a explicit LENGTH statement (or LENGTH= option on ATTRIB statement).
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.