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

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
novinosrin
Tourmaline | Level 20

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

View solution in original post

3 REPLIES 3
Criptic
Lapis Lazuli | Level 10

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

novinosrin
Tourmaline | Level 20

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
Ksharp
Super User
data _null_;
 do i=1 to 6;
  do j=1 to i;
   put 'P' @;
  end;
   put;
 end;
run;