I've attached a screenshot of my question, code and results above. The data I'm working with is a Space Delimited file. I'd like to provide some additional code that I've written that's also resulted in the same error:
data SwineFlu2009;
infile 'SwineFlu2009';
input idno 1-4 continent 13-18 country $ 27-59 date1 anydtdte10.60-70 num1 73-84 num2 86-93 num3 94-105 num4 106-115 num5 117-125
num6 126-135 num7 137-146 num8 149-156 date2 anydtdte32. 162-175 may 180-192 june 193-206 july 207-216 august 217-227
september 228-237 october 238-248 nov 250-259 dec 260-265;
run;
Obviously, nothing is showing up in DATE2 because either
Please examine your raw data file and see what is there.
By the way, we would prefer that type your message into the reply box, we don't need screen captures of text. SAS code should be pasted into the box that appears when you click on the running man icon. Thanks.
Hi there,
The RAW file has the date populated as YYYY-MM-DD (for example, 2009-08-23). There are, I believe, just one or two missing values, but apart from that the dates are populated.
Is there some obvious mistake in my code? Also, can you make out why the may-dec fields aren't being populated?
For context, I've attached my raw dataset with this message (it's very small since it's for learning purposes).
And thank you for information on formatting questions for this board. This was my first post, so not too familiar -- thanks!
Columns 162-175 do not contain anything recognizable as a date.
Is this the code you actually ran? Didn't it produce errors?
data SwineFlu2009;
infile 'SwineFlu2009';
input
idno 1-4
continent 13-18
country $ 27-59
date1 anydtdte10.60-70
num1 73-84
num2 86-93
num3 94-105
num4 106-115
num5 117-125
num6 126-135
num7 137-146
num8 149-156
date2 anydtdte32. 162-175
may 180-192
june 193-206
july 207-216
august 217-227
september 228-237
october 238-248
nov 250-259
dec 260-265
;
run;
Why do you have those two numbers separated by hyphens after the informat for date1 and date2. Also does date2 really take up 32 columns in your fixed column file? That seems like way too many for a date value. You probably want something more like:
...
@ 60 date1 anydtdte11.
...
@162 date2 anydtdte14.
@Tom wrote:
Why do you have those two numbers separated by hyphens after the informat for date1 and date2. Also does date2 really take up 32 columns in your fixed column file? That seems like way too many for a date value. You probably want something more like:
... @ 60 date1 anydtdte11. ... @162 date2 anydtdte14.
That would be fine and should work, except there is no date starting in column 162 in this data set, which needs to be fixed.
But yes, the LOG should contain errors which ought to also indicate the problem.
Also some of the text fields seem to have UTF-8 characters which will throw off the column counts.
It is not a good idea to try to create a fixed column file using characters that take a varying number of bytes per character.
Running your code example:
1764 data junk; 1765 input idno 1-4 continent 13-18 country $ 27-59 date1 anydtdte10.60-70 num1 73-84 num2 86-93 -- 22 76 1765! num3 94-105 num4 106-115 num5 117-125 ERROR 22-322: Syntax error, expecting one of the following: C, L, R.
This reads your text except for a couple of dates that I'm not going to try to figure out. I suspect that you may have more columns that aren't referenced correctly since your date starts were both off apparently.
data junk; input idno 1-4 continent 13-18 country $ 27-59 @61 date1 yymmdd10. num1 73-84 num2 86-93 num3 94-105 num4 106-115 num5 117-125 num6 126-135 num7 137-146 num8 149-156 @169 date2 yymmdd10. may 180-192 june 193-206 july 207-216 august 217-227 september 228-237 october 238-248 nov 250-259 dec 260-265;
Fixed column input does not allow you to specify the informat as you attempt for the date with columns and an informat. You could specify the columns and have an INFORMAT or ATTRIBUTE statement prior to the input to specify the informat or if your column usage lines up correctly skip the columns and use the informat.
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.