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

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

 

View solution in original post

5 REPLIES 5
data_null__
Jade | Level 19

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;
s_lassen
Meteorite | Level 14

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.

Tom
Super User Tom
Super User

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

 

s_lassen
Meteorite | Level 14

So it is really that simple? Thanks a lot!

Tom
Super User Tom
Super User

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1996 views
  • 2 likes
  • 3 in conversation