BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

In  my data I need to concatenate four variables. The output should have all values aligned in all rows to display in table. Please suggest. Thank you

output needed;

31(25) 37(14) 80.6 8.3

11(2)   12(7)   37.8 8.2

 

output getting

31(25) 37(14) 80.6 8.3

11(2) 12(7) 37.8 8.2

    data hav;
           input c1 $1-6 c2 $8-13 r1 $15-18 r2 $21-23 ;
           datalines;
31(25) 37(14) 80.6 58.3
11(2)  12(7)  37.8 18.2
           ;
           
           data want;
           set hav;
           tot=c1||"    "||c2||"    "||r1||"    "||r2;
           run;
2 REPLIES 2
Tom
Super User Tom
Super User

How are you printing the output?  If you use a proportional font then the spaces will use less width then the digits or other characters.

ballardw
Super User

Alignment is one of the reasons I do not create variables containing multiple values. With a separate variable I can use style overrides and custom formats to display columns in a tabular report, such as from Proc Report or Tabulate that aligns and appears to be single values to people without causing all the headaches of data maintenance that such composite valued variables can cause.

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 538 views
  • 0 likes
  • 3 in conversation