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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1988 views
  • 2 likes
  • 6 in conversation