DATA Step, Macro, Functions and more

How to create pyramid by using Base SAS programming? any one please help me.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

How to create pyramid by using Base SAS programming? any one please help me.

 

Accepted Solutions
Solution
‎09-17-2017 03:48 PM
Super User
Posts: 10,850

Re: How to create pyramid by using Base SAS programming? any one please help me.

Posted in reply to sandeep79
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


All Replies
Esteemed Advisor
Posts: 5,626

Re: How to create pyramid by using Base SAS programming? any one please help me.

Posted in reply to sandeep79

What is pyramid?

PG
Occasional Contributor
Posts: 6

Re: How to create pyramid by using Base SAS programming? any one please help me.

The output must be in pyramid shape.it has to be done in core coding by using do loop.
Occasional Contributor
Posts: 6

Re: How to create pyramid by using Base SAS programming? any one please help me.

[ Edited ]

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.

Frequent Contributor
Posts: 118

Re: How to create pyramid by using Base SAS programming? any one please help me.

Posted in reply to sandeep79
data _null_;
put '   *   ';
put '  ***  ';
put ' ***** ';
put '*******';
run;

Submit.  Find your pyramid erected inside the log.

Occasional Contributor
Posts: 6

Re: How to create pyramid by using Base SAS programming? any one please help me.

Posted in reply to ShiroAmada

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

Super User
Posts: 10,850

Re: How to create pyramid by using Base SAS programming? any one please help me.

Posted in reply to sandeep79
@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



Occasional Contributor
Posts: 6

Re: How to create pyramid by using Base SAS programming? any one please help me.

[ Edited ]

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.

Super User
Posts: 13,941

Re: How to create pyramid by using Base SAS programming? any one please help me.

Posted in reply to sandeep79

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)

 

Community Manager
Posts: 3,462

Re: How to create pyramid by using Base SAS programming? any one please help me.

Posted in reply to sandeep79

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?

Solution
‎09-17-2017 03:48 PM
Super User
Posts: 10,850

Re: How to create pyramid by using Base SAS programming? any one please help me.

Posted in reply to sandeep79
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;


☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 297 views
  • 1 like
  • 6 in conversation