BookmarkSubscribeRSS Feed
thanikondharish
Fluorite | Level 6

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?

2 REPLIES 2
Tom
Super User Tom
Super User

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
;

 

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
  • 2 replies
  • 1452 views
  • 1 like
  • 2 in conversation