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 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 516 views
  • 1 like
  • 2 in conversation