Obsidian | Level 7

## Write a program for character population

Question; Write a program to print like below based on input value;

Rawdata;

if input value P = 6; then output value should populate as below

Output Required;

P

PP

PPP

PPPP

PPPPP

PPPPP

My Code;

No idea;

Regards,

Calvin

1 ACCEPTED SOLUTION

Accepted Solutions
Tourmaline | Level 20

## Re: Write a program for character population

Hi @tsureshinvites   It's easy with REPEAT function.Have fun

``````%let n=100;
data want;
length want \$200;
do _n_=0 to &N;
WANT= repeat('P',_n_);
output;
end;
run;

proc print noobs;run;``````
want
P
PP
PPP
PPPP
PPPPP
PPPPPP
PPPPPPP
PPPPPPPP
PPPPPPPPP
PPPPPPPPPP
PPPPPPPPPPP
PPPPPPPPPPPP
PPPPPPPPPPPPP
PPPPPPPPPPPPPP
PPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPP
3 REPLIES 3
Lapis Lazuli | Level 10

## Re: Write a program for character population

Hey Calvin,

I'm not quite sure what you really need - I'm assuming you already read in the data - so lets call that data set input.

And you want to create a dataset with 6 rows per P=6 value in the input data set and they should contain one column which contains the values P, PP, PPP, PPPP, PPPPP (twice).

You can do this via a do-loop and using the output statement inside of the data step.

Example:

``````data work.result(drop=p i);
length x \$5.;
*set work.input;
p = 6;
if p = 6 then do;
do i = 1 to p - 1;
x = cats(x,'P');
output;
end;
output;
end;
run;``````

I hope this helps.

Kind regards

Criptic

Tourmaline | Level 20

## Re: Write a program for character population

Hi @tsureshinvites   It's easy with REPEAT function.Have fun

``````%let n=100;
data want;
length want \$200;
do _n_=0 to &N;
WANT= repeat('P',_n_);
output;
end;
run;

proc print noobs;run;``````
want
P
PP
PPP
PPPP
PPPPP
PPPPPP
PPPPPPP
PPPPPPPP
PPPPPPPPP
PPPPPPPPPP
PPPPPPPPPPP
PPPPPPPPPPPP
PPPPPPPPPPPPP
PPPPPPPPPPPPPP
PPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPP
Super User

## Re: Write a program for character population

``````data _null_;
do i=1 to 6;
do j=1 to i;
put 'P' @;
end;
put;
end;
run;``````
Discussion stats
• 3 replies
• 814 views
• 2 likes
• 4 in conversation