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. ![]()
I've used only three process: import, query and export.
Any help please ?
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
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
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
Hi Chris, thanks for your answer.
I prefer don't write code but I'll study your suggestion.
V.
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.
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
The RIGHT() function is not doing anything in that expression. PUT() always places the number on the right of the string.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.
Ready to level-up your skills? Choose your own adventure.