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;

sas-innovate-2024.png

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.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 814 views
  • 2 likes
  • 4 in conversation