I am reading some data from a .csv file, e.g.
infile input dsd delimiter=';';
Some of the rows are numeric data for a month. To read them I specify an informat:
informat JAN--DEC numx5.;
and then I read them using e.g.
input someothervariables JAN--DEC;
But a lot of the columns contain various errors (that's expected), so I would like to read using a ?? informat modifier.
But how can I do that when reading from a delimited file, using the informat in the INPUT statement like this
input someothervariables (JAN--DEC) (12*?? numx5.);
will make the informat "eat" a lot of the delimiters, and terrible things will happen. Any suggestions?
Since you already attached the INFORMAT you just need to use the ?? modifier in the INPUT statement.
input someothervariables (JAN--DEC) (??);
If you want to specify an INFORMAT in the INPUT statement and still process the line using LIST MODE input you need to use the : modifier. So include both the : and ?? modifiers. When reading in LIST MODE there is no need to specify a width on the informat, it will be ignored anyway as in LIST MODE the whole next word is read.
input someothervariables (JAN--DEC) (?? :numx.);
I think your main problem is defining the Month variable. You can't use -- to define a variable list.
In other words this cannot be used to define months Feb .. Nov
informat JAN--DEC numx5.;
Here use length statement then use double-dash list in INPUT statement.
data test;
infile cards dsd dlm=';' missover;
length Jan Feb Mar Apr May Jun 8;
input (jan--jun)(:numx. ??);
cards4;
1;2;3,4;x4;5;6;7
;;;;
run;
I do not have any problems defining the month variables, I do that with an informat statement, and afterwards I can input them and declare an array using the double dash notation.
Other than that, thanks for reminding me of the colon notation for informats, also a good solution.
Since you already attached the INFORMAT you just need to use the ?? modifier in the INPUT statement.
input someothervariables (JAN--DEC) (??);
If you want to specify an INFORMAT in the INPUT statement and still process the line using LIST MODE input you need to use the : modifier. So include both the : and ?? modifiers. When reading in LIST MODE there is no need to specify a width on the informat, it will be ignored anyway as in LIST MODE the whole next word is read.
input someothervariables (JAN--DEC) (?? :numx.);
So it is really that simple? Thanks a lot!
When using the (variable list) (format list) syntax in the INPUT statement the list of formats is recycled until the all of the variables are input. Just like the old FORTRAN IV FORMAT statement.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.