BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I thought that two below codes should work the same. However the second data step generates 0.175 and 0.1101 for the Grade variable while I assumed it had to generate 17.50 and 11.01 as the first data step does. Any idea why?

data StudentsGrades;
infile datalines;
input StudentName $
CourseName $
DateOfExam Date7.
Grade 5.2
Result $;
datalines;
George Math 19Dec05 1750 P
Susan Geography 01Feb05 1101 F
;
run;
data StudentsGradesDot1;
infile datalines dlm='.';
input StudentName $
CourseName $
DateOfExam Date7.
Grade 5.2
Result $;
datalines;
George.Math.19Dec05.1750.P
Susan.Geography.01Feb05.1101.F
;
run;

The results for the first data step:
George Math 16789 17.5 P
Susan Geograph 16468 11.01 F

The results for the second data step:
George Math 16789 0.175 P
Susan Geograph 16468 0.1101 F

Thanks,
Ramin
6 REPLIES 6
LinusH
Tourmaline | Level 20
For starters, having delimiters that can show up within the data often causes problems. I should try to get your file supplier to have the file delimited with something else.

If this is not feasible consider to read the whole record into a single string and then using different SAS character functions to read out your different columns.

Regards,
Linus
Data never sleeps
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
This is yet another anomaly with the "date" related INFORMAT handling. The fact that there is mixed INPUT processing is a contributing factor. My recommendation is to open a SAS support track, to let SAS Institute know that this unexpected input handling occurs when there is a date input field, and where the delimiter DOES NOT occur in the input record.

For illustration purposes, the two different input record types are processed, one containing a date field within the record and a second type without a date. SAS seems to handle the record not containing the date with no problem. See the code below:

data _null_;
infile datalines dlm='\';
format numdtvar1 date9.;
input type $ @;
if type ne ' ' then do;
if type = '1' then input charvar1 $ numdtvar1 anydtdte. numvar1 4.2 charvar2 $;
else
if type = '2' then input charvar1 $ numvar1 4.2 charvar2 $;
putlog _all_;
end;
datalines;
1\aaaa\01jan2008\2222\bbbb
2\aaaa\2222\bbbb
run;

Like I suggested, open a support track and stand your ground. Good luck.


Scott Barry
SBBWorks, Inc.
yonib
SAS Employee
You can use the informat statment

If i take your example its looks like this:

data b;
infile datalines dlm='.';
input StudentName $
CourseName $
DateOfExam Date7.
Grade
Result $;
informat Grade 5.2;
datalines;
George.Math.19Dec05.1750.P
Susan.Geography.01Feb05.1101.F
;
run;
BPD
Obsidian | Level 7 BPD
Obsidian | Level 7
To: RaminR

Use the informat modifier ':'.

This will read the variable content up to the next delimeter and then move the pointer to the next position after the delimeter. For some reason in your code SAS appears to be reading the '.' delimeter that separates values as part of the grade value.

In any event the following code works to read in the grade correctly. Be aware that you need to set your informats wide enough to accomodate the largest possible input to be read.

data StudentsGradesDot1;
infile datalines dlm='.';
input StudentName :$8.
CourseName :$9.
DateOfExam :Date7.
Grade :5.2
Result :$;
datalines;
George.Math.19Dec05.1750.P
Susan.Geography.01Feb05.1101.F
;
run;

Regards,

BPD
deleted_user
Not applicable
Thanks BPD. That seems like a better way to handle these kind of ambiguities.
Ramin
Peter_C
Rhodochrosite | Level 12
In this statement [pre] input StudentName :$8.
CourseName :$9.
DateOfExam :Date7.
Grade :5.2
Result :$; [/pre] remove the explicit/implied decimal 2 from the grade informat. Then it would be like[pre] Grade :5. [/pre]
Much safer I feel,is to predefine stored variable lengths (and then informats) before the INPUT statement, which won't then need informats defined at all.

Good Luck

PeterC just spelling!

Message was edited by: Peter.C

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 724 views
  • 0 likes
  • 6 in conversation