Range of charater variables in an INFILE statement

Accepted Solution Solved
Reply
Contributor
Posts: 66
Accepted Solution

Range of charater variables in an INFILE statement


Hi experts,

I have a csv file that has 100s of  identical variables(columns) andare all character fields.

This is my attempt to read them -I do not  want to list each of them in Input statement;

Data Have;

Infile "abc/xys/aabb.csv" dsd firstobs=2;

INPUT  Fname $    Age   LName Var1-Var100;

The variable list Var1-Var100 works only for numeric variables. How do I get around if all these variables are characters?

I tried

INPUT  Fname $    Age   LName Var1-Var100 $ , this works only for the last variable but not for remaining 99. And if I do

INPUT  Fname $    Age   LName Var1 $ -Var100 $;....it throws an error.

Please suggest.


Accepted Solutions
Solution
‎12-31-2014 01:46 PM
PROC Star
Posts: 7,439

Re: Range of charater variables in an INFILE statement

try: (var-var100) ($)

But I'd think that LName is also a character variable thus it should probably have a $ after it

View solution in original post


All Replies
Solution
‎12-31-2014 01:46 PM
PROC Star
Posts: 7,439

Re: Range of charater variables in an INFILE statement

try: (var-var100) ($)

But I'd think that LName is also a character variable thus it should probably have a $ after it

Super User
Super User
Posts: 6,851

Re: Range of charater variables in an INFILE statement

It is much easier if you define the variables first and then write the INPUT statement.

data want ;

  infile 'myfile.csv' dsd firstobs=2 lrecl=30000 truncover ;

  length fname $20 age 8 lname $20 var1-var100 $20 ;

  input fname -- var100  ;

run;

You can also use () to apply a format to multiple variables.

input .... (var1-var100) ($) ;

Contributor
Posts: 66

Re: Range of charater variables in an INFILE statement

Tom and Art,

Thanks for  help!!!!!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 233 views
  • 4 likes
  • 3 in conversation