Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7560705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:58:19+00:00 2026-05-30T12:58:19+00:00

I am creating a SAS dataset from a database that includes a VARCHAR(5) key

  • 0

I am creating a SAS dataset from a database that includes a VARCHAR(5) key field.

This field includes some entries that use all 5 characters and some that use fewer.

When I import this data, I would prefer to pad all the shorter entries out to use all five characters. For this example, I want to pad on the left with 0, the character zero. So, 114 would become 00114, ABCD would become 0ABCD, and EA222 would stay as it is.

I’ve attempted this with a simple data statement, but of course the following does not work:

data test;
    set databaseinput;
    format key $5.;
run;

I’ve tried to do this with a user-defined informat, but I don’t think it’s possible to specify the ranges correctly on character fields, per this SAS KB answer. Plus, I’m fairly sure proc format won’t let me define the result dynamically in terms of the incoming variable.

I’m sure there’s an obvious solution here, but I’m just missing it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:58:20+00:00Added an answer on May 30, 2026 at 12:58 pm

    Here is an alternative:

    data padded_data_dsn; length key $5;
        drop raw_data;
        set raw_data_dsn(rename=(key=raw_data));
        key = translate(right(raw_data),'0',' ');
    run;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Support.sas.com provides this syntax for creating a prediction ellipse. The output dataset includes only
I am creating a script that will show your computer information in Non-Geekeese. This
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
Creating a server-side socket will fail if I'm trying to use the same port
In my custom component I created some TAction-s as subcomponents. They're all published, but
I'm trying to use 'adonet.batch_size' property in NHibernate. Now, I'm creating entities across multiple
Creating a calculator-like dialog, I noticed that quickly clicking on a button in IE
Is it possible to use raw SQL rather than the TABLE construct for creating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.