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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.