BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
OK. How about this one .



data have;
input x $;
n=0;
do i=length(x) to 1 by -1;
 n+1;
 if mod(n,2)=0 then substr(x,length(x)-n+1,1)=' ';
 y=reverse(substr(x,2))||x; 
end;
cards;
*
**
***
****
*****
;
run;


View solution in original post

10 REPLIES 10
sandeep79
Calcite | Level 5
The output must be in pyramid shape.it has to be done in core coding by using do loop.
sandeep79
Calcite | Level 5

HI PG,
> >
> > I have a below values in data set and how can i build pyramid?
> > *
> > **
> > ***
> > ****
> > *****
> >
> > i want to move first row to start at position 5 and later on decreasing
> as
> > moving to next record.
> > My output should be this way.
> >
> >        *
> >       * *
> >      * * *
> >    * * * *
> >   * * * * *
> >  * * * * * *
> >
> > please help out.

ShiroAmada
Lapis Lazuli | Level 10
data _null_;
put '   *   ';
put '  ***  ';
put ' ***** ';
put '*******';
run;

Submit.  Find your pyramid erected inside the log.

sandeep79
Calcite | Level 5

i have to get the output by hard coding (by doing iterations).

Ksharp
Super User
@Rick make many different type of Christmas tree .


http://blogs.sas.com/content/iml/2013/12/18/christmas-tree-matrix.html

http://blogs.sas.com/content/iml/2014/12/10/xmas-tree-pascals-triangle.html



sandeep79
Calcite | Level 5

Hi ksharp,
Thanks for helping me,
pyramid must be build using normal coding not by matrix or graph plot.
> >
> > I have a below values in data set and how can i build pyramid?
> > *
> > **
> > ***
> > ****
> > *****
> >
> > i want to move first row to start at position 5 and later on decreasing
> as
> > moving to next record.
> > My output should be this way.
> >
> >      *
> >     * *
> >    * * *
> >   * * * *
> >  * * * * *
> > * * * * * *
> >
> > please help out.

ballardw
Super User

@sandeep79 wrote:

Hi ksharp,
Thanks for helping me,
pyramid must be build using normal coding not by matrix or graph plot.


How are graph plots "abnormal"?

 

What is your destination? A text file? HTML? RTF? PDF?

Note that the FONT used to display the output can result in an uneven appearance because of the way spaces may be displayed with proportional fonts (which is one possible reason to use graphic output)

 

ChrisHemedinger
Community Manager

Sounds like an algorithm puzzle.  Perhaps a class assignment?

 

Given a list of records with asterisks left-aligned, build a pyramid (centered) version of these records?  Sounds like you need to:

  1. Learn the length of the longest record (let's call it X)
  2. Pad each record with spaces on either side of the asterisks -- prepend and append X/2 - length(trim(current_record)), adjusting by one when that length is an even number.

It could be a fun little programming golf puzzle...but maybe people would be more inclined to help if they knew this wasn't just your homework?  Or an interview question?  Is there a business goal?

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
Ksharp
Super User
OK. How about this one .



data have;
input x $;
n=0;
do i=length(x) to 1 by -1;
 n+1;
 if mod(n,2)=0 then substr(x,length(x)-n+1,1)=' ';
 y=reverse(substr(x,2))||x; 
end;
cards;
*
**
***
****
*****
;
run;


sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1891 views
  • 2 likes
  • 6 in conversation