Desktop productivity for business analysts and programmers

Right aligned numeric fields doing export on TXT fixed lenght using schema.ini

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Right aligned numeric fields doing export on TXT fixed lenght using schema.ini

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 ?  


Accepted Solutions
Solution
‎08-06-2013 10:02 AM
Trusted Advisor
Posts: 1,052

Re: Right aligned numeric fields doing export on TXT fixed lenght using schema.ini

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


All Replies
Solution
‎08-06-2013 10:02 AM
Trusted Advisor
Posts: 1,052

Re: Right aligned numeric fields doing export on TXT fixed lenght using schema.ini

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

Community Manager
Posts: 2,693

Re: Right aligned numeric fields doing export on TXT fixed lenght using schema.ini

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

New Contributor
Posts: 3

Re: Right aligned numeric fields doing export on TXT fixed lenght using schema.ini

Hi Chris, thanks for your answer. 

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

V.

New Contributor
Posts: 3

Re: Right aligned numeric fields doing export on TXT fixed lenght using schema.ini

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.

Trusted Advisor
Posts: 1,052

Re: Right aligned numeric fields doing export on TXT fixed lenght using schema.ini

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

Super User
Super User
Posts: 6,323

Re: Right aligned numeric fields doing export on TXT fixed lenght using schema.ini

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 680 views
  • 0 likes
  • 4 in conversation