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
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 |
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
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 |
data _null_;
do i=1 to 6;
do j=1 to i;
put 'P' @;
end;
put;
end;
run;
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.