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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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-2024.png

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.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

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