BookmarkSubscribeRSS Feed
sasiroyal
Calcite | Level 5

Hi  , 

 

data ds;

input x $ y $ z $; 

cards; 

ram is agoodboy

run; 

 

output: 

               z                      a

ram   is     agoodboy          ram

                                                is

                                                 agoodboy

 

It is only one observation in the final output. 

 

 

Anyone can help me how to get this output ? 

3 REPLIES 3
Reeza
Super User
So a is the text with linefeeds? AFAIK there isn't a way to store data like that in a data set, but you can print it that way in a report or export to RTF. Not sure about Excel.

That's what would be called a display format, not a storage format.
Sajid01
Meteorite | Level 14

Please see this post that has the solution to your issue.

https://communities.sas.com/t5/SAS-Programming/Override-space-as-delimiter-in-reading-text-files/td-...
With the above post in mind, your code would be like this.

DATA ds ;
  ATTRIB a LENGTH = $200 ;
  INFILE datalines TRUNCOVER;
  INPUT a $char200.;
  datalines;
ram is a good boy
; 
RUN ;
ballardw
Super User

If the question is "how do I insert carriage return and/or linefeed characters between values of a single variable the answer would be the CATX function. But the data set viewer won't honor them and they may get treated oddly by different display formats, RTF, PDF, HTML depending on the exact syntax used to display them.

 

data ds;
   input x $ y $ z $; 
   a=catx('0D'x,x,y,z); 
   output;
cards; 
ram is agoodboy
; 

proc print data=ds;
var x y z;
var a /style=[asis=on];
run;

But if you don't use the style override in Print the variable A appears on one line with spaces between bits.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

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