data date;
input Patent_ID Age Date_of_admission;
informat Date_of_admission ddmmyy10.;
format Date_of_admission ddmmyy10.;
cards;
100 56 02/03/1985
200 65 02.03.1986
300 76 02-05-1987
400 82 02.04.1988
;
run;
proc print data=date;
run;
I don't see anything wrong with this code. It runs correctly for me.
Please go back and change the subject line to be a meaningful subject for your post. "Please correct the code" could apply to 95% of the posts here.
hi, Thanks for quick reply. But the output and result are not showing correct result. I could see only two observations i.e first and last one.
@Prasad-S wrote:
hi, Thanks for quick reply. But the output and result are not showing correct result. I could see only two observations i.e first and last one.
I run your code unchanged. I see four records when I do the PROC PRINT. Please show us the output you are seeing. Please fix the subject line in the original post.
Please copy the log from the SAS log window (just for the entire DATA step, we don't need the rest) and paste it into the window that appears when you click on the </> icon.
If you read this part of your log:
NOTE: Invalid data for Patent_ID in line 75 1-6. NOTE: Invalid data for Age in line 75 8-17. NOTE: Invalid data for Date_of_admission in line 76 1-3. RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 76 300 76 02-05-1987 NOTE: Invalid data errors for file CARDS occurred outside the printed range. NOTE: Increase available buffer lines with the INFILE n= option. Patent_ID=. Age=. Date_of_admission=. _ERROR_=1 _N_=2
You see that the first three lines tell you that a Date_of_admission was read from line 76 when the other two variables were read from line 75. Combine that with the "occurred outside the printed range" one starts to suspect that there are non-printable characters in you code that are not there after pasting into this forum.The indication of reading across lines means that something is interpreted as an end of line and or carriage return depending on your operating system and version of SAS.
The main message windows on this forum reformat pasted text. So the reformatting may have removed or combined your non-printable characters resulting in code that when we copy it will execute.
If you copied any or all of your datalines from another program that is a very likely source of non-printable characters and you may need to actually type the example data, or start deleting/entering spaces between any problem values.
@Prasad-S wrote:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;6869 data date;70 input Patent_ID Age Date_of_admission;71 informat Date_of_admission ddmmyy10.;72 format Date_of_admission ddmmyyb10.;73 cards;NOTE: Invalid data for Patent_ID in line 75 1-6.NOTE: Invalid data for Age in line 75 8-17.NOTE: Invalid data for Date_of_admission in line 76 1-3.RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----076 300 76 02-05-1987NOTE: Invalid data errors for file CARDS occurred outside the printed range.NOTE: Increase available buffer lines with the INFILE n= option.Patent_ID=. Age=. Date_of_admission=. _ERROR_=1 _N_=2NOTE: SAS went to a new line when INPUT statement reached past the end of a line.NOTE: The data set WORK.DATE has 3 observations and 3 variables.NOTE: DATA statement used (Total process time):real time 0.00 secondsuser cpu time 0.00 secondssystem cpu time 0.00 secondsmemory 666.53kOS Memory 21156.00kTimestamp 01/09/2023 03:27:50 PMStep Count 31 Switch Count 2Page Faults 0Page Reclaims 135Page Swaps 0Voluntary Context Switches 10Involuntary Context Switches 0Block Input Operations 0Block Output Operations 26478 ;79 run;8081 proc print data=date;82 run;NOTE: There were 3 observations read from the data set WORK.DATE.NOTE: PROCEDURE PRINT used (Total process time):real time 0.01 secondsuser cpu time 0.01 secondssystem cpu time 0.00 secondsmemory 1146.21kOS Memory 21156.00kTimestamp 01/09/2023 03:27:50 PMStep Count 32 Switch Count 0Page Faults 0Page Reclaims 80Page Swaps 0Voluntary Context Switches 0Involuntary Context Switches 0Block Input Operations 0Block Output Operations 8
Thanks for the log, but the problem is on the line of data BEFORE the one that is being listed. Basically the issue seems to be that it did not find a value of the date on the line before so it is hunting for one on the line it is showing.
If the problem is just that one of the lines is missing a date value you might only need to add an INFILE statement so you can use the TRUNCOVER option to prevent INPUT from going to the next line.
data date;
infile cards truncover;
input Patent_ID Age Date_of_admission;
informat Date_of_admission ddmmyy10.;
format Date_of_admission ddmmyyb10.;
cards;
Or you can just add a single period on the data lines to indicate when one of the three fields is missing.
See the third line of data in this example:
data date;
input Patent_ID Age Date_of_admission;
informat Date_of_admission ddmmyy10.;
format Date_of_admission ddmmyy10.;
cards;
100 56 02/03/1985
200 65 02.03.1986
300 76 .
400 82 02.04.1988
;
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.