I have some data like
1 2 3 ...
A B C ...
The first row are some numbers and the second row are the corresponding string value.
I want input them into SAS as a dataset but I just don't success. The desire output should be like:
1 A
2 B
3 C
Here is what I have tried:
data test;
do i = 1 to 3;
input @(2*i-1) RANDNO #2 @(2*i-1) GROUP$;
output;
end;
cards;
1 2 3
A B C
;
run;
Please help.
Do you always have two rows?
Is the number of columns fixed, or arbitrary?
And most important: is this a SAS dataset, or an external text file?
Thank for your reply.
1. No. there can more rows. Data looks like this:
1 2 3
A B C
4 5 6
D E F
...
2. It is fixed at 3.
3. It is read from SAS datalines, not external files.
See this:
data want;
array numval {3} _temporary_;
array charval{3} $ _temporary_;
length randno 8 groups $8;
do i = 1 to 3;
input numval{i} @;
end;
input;
do i = 1 to 3;
input charval{i} @;
end;
do i = 1 to 3;
randno = numval{i};
groups = charval{i};
output;
end;
keep randno groups;
datalines;
1 2 3
A B C
4 5 6
D E F
;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.