BookmarkSubscribeRSS Feed
whymath
Lapis Lazuli | Level 10

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.

3 REPLIES 3
whymath
Lapis Lazuli | Level 10

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.

Kurt_Bremser
Super User

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
;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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