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

I have attempted various methods, but I have been unable to obtain the desired output.

Using do loops 

I need output like following; 
1
121
12321
1234321
123454321

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Is the output one variable? Is it numeric or character? Maximum of 5 or how many rows? (Will severely limit whether the value is numeric or not

This makes a character value with that appearance.

data example;
   length var $ 25;
   do levels = 1 to 5;
      call missing(var);
      do j=1 to levels;
         var=cats(var,j);
      end;
      do j=(levels-1) to 1 by (-1);
         var=cats(var,j);
      end;
      output;
   end;
   drop levels j;
run;

View solution in original post

3 REPLIES 3
LinusH
Tourmaline | Level 20
Is this some kind of training assignment?
The task doesn't reflect what you normally do using SAS...
Data never sleeps
ballardw
Super User

Is the output one variable? Is it numeric or character? Maximum of 5 or how many rows? (Will severely limit whether the value is numeric or not

This makes a character value with that appearance.

data example;
   length var $ 25;
   do levels = 1 to 5;
      call missing(var);
      do j=1 to levels;
         var=cats(var,j);
      end;
      do j=(levels-1) to 1 by (-1);
         var=cats(var,j);
      end;
      output;
   end;
   drop levels j;
run;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 180 views
  • 1 like
  • 4 in conversation