BookmarkSubscribeRSS Feed
brophymj
Quartz | Level 8

I'm reading in a txt file into sas and write up the fields and attributes in columns in excel and then copy and paste into sas. However, the columns don't line up in sas. Is there a way to paste the data so that it looks like...

driver_cat              $10.;

age                        $5.;

....

instead of

driver_cat $10.;

age  $5.;                      

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Why would you want to be copying code from and Excel file in the first place?  Integrated Development Environments and text editors are the tools for coding. 

Your problem lies in the fact that Excel has cells, nothing else has this concept.  When you copy it takes the text out of those cells, puts a space in between and then keeps it on the clipboard.  When you paste this text then gets pasted in the SAS text file.  I know that some of the more modern IDEs allow textual alignments to markers (a bit like Word where you can move the ticks at the top and align text to that), but at least up to 9.3 I don't think this was possible.  My suggestion - avoid using Excel for anything.

brophymj
Quartz | Level 8

Are there text editor tools in SAS?

Ksharp
Super User

If you are using SAS University Edition, there is a tool button named 'Formate code' to make your code readable .

brophymj
Quartz | Level 8

I have sas 9.3 - is there something there where you can just paste a columns of fields and then another columns of attributes in such a way that they are aligned.

Thanks

RW9
Diamond | Level 26 RW9
Diamond | Level 26

There is the Enhanced Editor and basic Editor.  Neither of which has alignment controls other than to put spaces instead of tabs.  What are you trying to do though?  If its just a parameter list, put it in a text file and %include or infile it in, doesn't seem to be much point in copy/pasting it.

Reeza
Super User

EG also has a format your code option.

TWo other things to try:

1. Cut and paste each column using ALT key. I think this works but not in front of SAS to try.

2 Create the appropriate text in Excel using Concatenate and length functions before pasting to SAS.

TomKari
Onyx | Level 15

Whenever I need to do this, I do it in Excel.

Assuming that my variable name is in cell A1, and my length in B1, the formula

=MID(A1&REPT(" ",20),1,20)&B1

should give you attractive output. Substitute whichever number looks good for the two instances of 20.

Tom

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 8 replies
  • 3617 views
  • 2 likes
  • 6 in conversation