Merik
Merik

Reputation: 2827

Numbered range variables with character type

I have an INPUT statement that reads similar to this:

INPUT FOO BAR CHR1 $ CHR2 $ CHR3 $ CHR4 $ CHR5 $ BLAH;

CHR1 to CHR5 are all character variables (not numeric). If they were numeric, I could simplify it using a numbered range to CHR-CHR5 but because they are character variables, I don't know how to shorten the INPUT command. I tried this:

INPUT FOO BAR CHR1-CHR5 $ BLAH;

But it tries to read them as numeric variables, not as character variables, which results in incorrect data loading.

How can I import a range of character variables and assign them consecutive names?

Upvotes: 0

Views: 50

Answers (2)

data _null_
data _null_

Reputation: 9109

INPUT FOO BAR (CHR1-CHR5)($) BLAH;

Upvotes: 2

Parfait
Parfait

Reputation: 107687

Consider using an array with the input (below is a comma delimited infile example):

data databases;
    infile datalines DSD;
    array databases(1:5) $15 CHR1-CHR5;
    input databases(*);

    datalines;
    Oracle, SQL Server, PostgreSQL, MySQL, DB2
;
run;

Upvotes: 0

Related Questions