Solved
Contributor
Posts: 22

# repeat letter

Good morinig,

I have a column contains single letters and another number of repetition n.
I want to create a new column that will take value of letters multiply by  n
example.

data have;

input var1 \$1 nbr;

cards;

a  3

b  5

c  2

;run;

I want:

data want

var1  nbr  nvar

a      3      aaa

b      5      bbbbb

c      2      cc

thank you

Accepted Solutions
Solution
‎06-13-2017 01:00 PM
PROC Star
Posts: 1,218

## Re: repeat letter

[ Edited ]

Like this?

``````data have;
input var1 \$1 nbr;
cards;
a 3
b 5
c 2
;

data want;
set have;
nvar = repeat(var1, nbr-1);
run;``````

All Replies
Solution
‎06-13-2017 01:00 PM
PROC Star
Posts: 1,218

## Re: repeat letter

[ Edited ]

Like this?

``````data have;
input var1 \$1 nbr;
cards;
a 3
b 5
c 2
;

data want;
set have;
nvar = repeat(var1, nbr-1);
run;``````
Super User
Posts: 13,358

## Re: repeat letter

If you don't want to have a variable defaulting to 200 characters, OR you need the result to be longer than 200 you will want to have a LENGTH statement to assign a desired length to the result variable.

Super User
Posts: 10,699

## Re: repeat letter

``````data have;
input var1 \$1 nbr;
rep=repeat(var1,nbr-1);
cards;
a  3
b  5
c  2
;
run;``````
PROC Star
Posts: 504

## Re: repeat letter

repear function should work

```data want;
set have;
nvar=repeat(var1,nbr-1);
run;```
Contributor
Posts: 22

Super User
Posts: 23,346