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...

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!

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.

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
  • 1206 views
  • 8 likes
  • 4 in conversation