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
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;
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;
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.
data have;
input var1 $1 nbr;
rep=repeat(var1,nbr-1);
cards;
a 3
b 5
c 2
;
run;
repear function should work
data want; set have; nvar=repeat(var1,nbr-1); run;
Thank you for your answer
@mansour_ibrahim Please mark one of the solutions as the answer.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.