BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mansour_ibrahim
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

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;
ballardw
Super User

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.

Ksharp
Super User
data have;
input var1 $1 nbr;
rep=repeat(var1,nbr-1);
cards;
a  3
b  5
c  2
;
run;
kiranv_
Rhodochrosite | Level 12

repear function should work

data want;
set have;
nvar=repeat(var1,nbr-1);
run;
mansour_ibrahim
Obsidian | Level 7

Thank you for your answer

Reeza
Super User

@mansour_ibrahim Please mark one of the solutions as the answer. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 6 replies
  • 1087 views
  • 0 likes
  • 6 in conversation