BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
runrunbunny
Obsidian | Level 7

 

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 !!!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

15 REPLIES 15
Astounding
PROC Star
The results you describe do not add up.

YEARCUTOFF has no impact when you are using 4-digit years. It only applies when you use 2-digit years.

All in all, I suspect you mistakenly used the date7 informat instead of the date9 informat.
runrunbunny
Obsidian | Level 7

Thank you so much

But I'm 100% sure I used date9. informat

Patrick
Opal | Level 21

@runrunbunny 

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;

Capture.JPG

runrunbunny
Obsidian | Level 7

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; 

 

 

 

ChrisNZ
Tourmaline | Level 20

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.

 

 

runrunbunny
Obsidian | Level 7

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; 

Astounding
PROC Star

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.

runrunbunny
Obsidian | Level 7

Thanks a million!! 

What's the meaning by adding a comma in the middle of DOB and Date9. ?

runrunbunny
Obsidian | Level 7

sorry, what's the meaning by adding a colon between DOB and Date9. ?

Astounding
PROC Star

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.

runrunbunny
Obsidian | Level 7

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; 

ballardw
Super User

@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;
runrunbunny
Obsidian | Level 7

Impressive example and now I get it.

Thank you so much !!!

Tom
Super User Tom
Super User

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).

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 15 replies
  • 1514 views
  • 6 likes
  • 6 in conversation