BookmarkSubscribeRSS Feed
whymath
Barite | Level 11

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
Barite | Level 11

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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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