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
;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 935 views
  • 1 like
  • 2 in conversation