data have ;
infile cards dlm=',' ;
input (a1-a4) ($10.) ;
cards ;
a ,b, c, d
;
is the above program correct to assign length to all character variables at a time
if it is wrong then how can i do?
The way to assign a length to a variable is to use a LENGTH statement. You can also use the LENGTH= attribute in an ATTRIB statement.
length A1-A4 $10 ;
If you want to let the compiler GUESS what length you want to use for your variables based on how you first use them then you could use your method of using an informat in the INPUT statement. But for delimited data make sure to use the colon modifier to prevent the INPUT statement from using formatted input mode and messing up the parsing of the line around the delimiters.
data have ;
infile cards dsd dlm=',' truncover;
input (a1-a4) (:$10.) ;
cards ;
a,b,c,d
;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.