Write and run SAS programs in your web browser

Print observations in a row

Reply
Contributor
Posts: 26

Print observations in a row

Hello everyone,

 

When I want to print all observations under a variable, it prints them in a column format (i.e., each observation is listed right below the previous one). However, how can I print all observations in a row format (i.e., all observations are listed adjasent to each other)?

 

Any idea/thought is really appreciated!

 

 

Super User
Posts: 18,588

Re: Print observations in a row

You'll need to manually use a PUT statement within a data step to control your output. 

Or you could select the row, transpose your data and then use PROC PRINT. 

If this is something you do regularly I'd probably create a macro to handle this issue.

Contributor
Posts: 26

Re: Print observations in a row

I'd be very thankful if you can create a macro, because this is not going to be a one-time SAS code for me.
Super User
Posts: 10,874

Re: Print observations in a row

Show an example starting data set and the desired resulting data set.

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against. 

 

Super User
Posts: 18,588

Re: Print observations in a row


Alireza_Boloori wrote:
I'd be very thankful if you can create a macro, because this is not going to be a one-time SAS code for me.

I'm happy to help, not to write your code. If this is not a one time use you should also understand it thoroughly. I suggest coding it for a 'Base case' then we can help you turn it into a macro. For example, how to get all Names from SASHELP.CLASS on a single line. You didn't want any delimiter between the values? 

 

See the PUT Statement Documentation for examples

 http://support.sas.com/documentation/cdl/en/lestmtsref/69738/HTML/default/viewer.htm#n1spe7nmkmi7ywn...

 

Ask a Question
Discussion stats
  • 4 replies
  • 138 views
  • 0 likes
  • 3 in conversation