Input string with an unknown variable length

I need to input a string variable from a csv file that can be of any length from 0 to 32K characters. The maximum length is unkown at the time of import and I would like to set the variable size to the actual maximum length in the csv file. So I think I need to use $varyingw but looking at examples it seems like the length needs to be defined in the input file or is set to the record length. What is the best way of inputting this field?

Re: Input string with an unknown variable length

Thanks Tom. So is there any disc space issues in setting the length so big? Also, if the maximum length was 259 characters (for example, but I dont know this beforehand) is there is no way I can implement the input statement to default to 259 when executed?

Re: Input string with an unknown variable length

If you know that the maximum possible length then define the variable using that length. So in my example change the 32767 (which is maximum possible variable length) to 259. You can also change the LRECL on the INFILE statement, but I doubt that would have much impact on performance.

SAS stores all character variables as fixed length. But if you use the COMPRESS dataset option then the extra empty space does not take much space on the disk.