BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
loky
Calcite | Level 5

Hi all,

I'm doing a query between two sequential files that i've imported in sas using "sas enterprise guide".

The result is a new dataset that i must export in a sequential txt fixed lenght.

I've used the file schema.ini to defined the type and the lenght of all the fileds.

I'm not able to put  numeric fileds right aligned. Smiley Sad

I've used only three process: import, query and export.

Any help please ?  

1 ACCEPTED SOLUTION

Accepted Solutions
TomKari
Onyx | Level 15

Hi, Loky

Here's a workaround you can use, by converting your numbers to right-aligned character fields BEFORE exporting them.

Start a new query on your file, and add all of the fields EXCEPT your numbers to the "Select Data" pane.

Now, for each number that you want right aligned:

Create a new advanced expression;

In the advanced expression, enter

     right(put(xxxxx, 5.))

where xxxxx is your variable name, and 5 is the number of characters you want the field to occupy.

Finish defining the advanced expression, and when you run the query you should have a correctly defined character field, that you can export.

Tom

View solution in original post

6 REPLIES 6
TomKari
Onyx | Level 15

Hi, Loky

Here's a workaround you can use, by converting your numbers to right-aligned character fields BEFORE exporting them.

Start a new query on your file, and add all of the fields EXCEPT your numbers to the "Select Data" pane.

Now, for each number that you want right aligned:

Create a new advanced expression;

In the advanced expression, enter

     right(put(xxxxx, 5.))

where xxxxx is your variable name, and 5 is the number of characters you want the field to occupy.

Finish defining the advanced expression, and when you run the query you should have a correctly defined character field, that you can export.

Tom

ChrisHemedinger
Community Manager

If you're willing to write a little bit of code, you will find that you have more flexibility in creating a flat file in the exact format that you need using DATA step.

Then you can automate the "transfer" of that file from SAS to your local PC using this technique:

Export and download any file from SAS Enterprise Guide - The SAS Dummy

Chris

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
loky
Calcite | Level 5

Hi Chris, thanks for your answer. 

I prefer don't write code but I'll study your suggestion.

V.

loky
Calcite | Level 5

Hi TomKari, you have open me a world.

I've modified your advanced expression to right aligned and to replace space with zero.

translate(right(put(nameofthefield, numberofcharacter.)),"0"," ")

Thanks a lot.

V.

TomKari
Onyx | Level 15

Hey, Loky

Glad I could help. Functions and formats in SAS are amazing!

Instead of

translate(right(put(xxxxx, 5.)),"0"," ")

try

put(nameofthefield, z5.)

The zn. format in SAS automatically zero-fills the number.

Best,

  Tom

Tom
Super User Tom
Super User

The RIGHT() function is not doing anything in that expression. PUT() always places the number on the right of the string.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 6 replies
  • 3519 views
  • 0 likes
  • 4 in conversation