Reputation: 961
I can create a Numbered Range List of numeric type, but not character type.
My code is similar to this:
DATA TestDataset;
INPUT a1-a3 $;
DATALINES;
A B C
;
RUN;
This produces 3 variables - [a1], [a2] and [a3] as expected. However [a3] is character, but [a1] and [a2] are numeric. This leaves me with missing values as per the following table:
a1 a2 a3
. . C
The following code works, but obviously it does not scale nicely.
INPUT a1 $ a2 $ a3 $;
Am I missing something?
Upvotes: 1
Views: 2732
Reputation: 10843
I came up with a macro solution:
%MACRO var_list_char (var_prefix, n);
%LOCAL i ;
%DO i = 1 %TO &n;
&var_prefix&i$
%END;
%MEND;
DATA TestDataset;
INPUT %var_list_char (a, 3);
DATALINES;
A B C
;
RUN;
I wish I could find a way to do this without macros - I will keep digging for a bit and will update this post if I find more. In the meantime, the above approach will definitely work.
UPDATE 1: @carolinajay65's solution above is the correct non-macro approach.
UPDATE 2: There is another way that I found.
DATA TestDataset;
INPUT (a1-a3) ($);
DATALINES;
A B C
;
RUN;
More documentation of the language features supporting this technique can be found here, in the section labeled "How to Group Variables and Informats".
Upvotes: 4
Reputation: 28411
I believe you can use the hyphen notation on the length statement to get what you want. You really should use a length statement regardless..otherwise it defaults to $8.
DATA TestDataset;
length a1-a3 $20;
INPUT a1-a3 ;
DATALINES;
A B C
;
RUN;
Upvotes: 4