BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
allurai0412
Fluorite | Level 6


hi,

I am providing a sample of dataset that I am working with...

I want threee zeros to be added to "id" in the ouput dataset;

DATA HAVE;

INFILE DATALINES;

INPUT ID NAME : $ AMOUNT;

DATALINES;

1 ALIERN 4500

2 VEREKR 20000

3 RERRRR 100000

;

RUN;

******************************

REQUIED OUTPUT;

00001 ALIERN 4500

00002 VEREKR 20000

00003 RERRRR 100000

Regards

ALLU

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

Not INFORMAT reading is not the issue.  You want to SEE it with leading zeros.

FORMAT AGE z5.;

You might want to consult the documentation!

View solution in original post

6 REPLIES 6
VD
Calcite | Level 5 VD
Calcite | Level 5

data get;

  format id2 $5.;

  set have;

  id2= '000'||strip(id);

  rename id2=id;

  drop id;

run;

allurai0412
Fluorite | Level 6

thanks VD..

it is working...just i added another like

id2= '0000'||strip(id);

regards..

ALLU

Keith
Obsidian | Level 7

If it's for display purposes and you want to keep the id column as numeric, then just use the Zw.d format which pads the values with leading zeros.

e.g. format id z5.;

By the way, in your required output, you've added 4 zeros not 3.

allurai0412
Fluorite | Level 6

Hi keith,

I am getting error....

will you please look in to the issue...

Regards

ALLU

448  data school;

449  input Age format z5. Quiz : $1. Midterm Final;

                      ---

                      48

ERROR 48-59: The informat Z was not found or could not be loaded.

450

451  id2= '000'||strip(age);

452  if  age=12 then grade=6;

453   else  if age=13 then grade=8;

454  datalines;

data_null__
Jade | Level 19

Not INFORMAT reading is not the issue.  You want to SEE it with leading zeros.

FORMAT AGE z5.;

You might want to consult the documentation!

allurai0412
Fluorite | Level 6

thanks...

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2201 views
  • 8 likes
  • 4 in conversation