BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
data ds;
input id;
y=(X ,pd4.);
cards;
'1234'

;
run;

Result

 

00001234

8 REPLIES 8
Kurt_Bremser
Super User

Please do yourself a favor and test code before you post it here. Your code makes my eyes water, and it forces me to assume you do not have the slightest grasp about SAS software at all.

Do yourself an even bigger favor, and work through the free online Programming 1 e-course, so you will have at least a basic understanding of the most essential elements of the SAS language.

 

Try this:

data test;
input id_num;
format id_num z8.; /* just for display */
id_char = put(id_num,z8.); /* storing ID values as character is preferred */
datalines;
1234
;

 

 

PS I edited your original subject line back in, as there is no pd4. function in SAS. Once again, take the online Programming 1 course. Really. I mean it.

BrahmanandaRao
Lapis Lazuli | Level 10
PDw.d Format y=put(x,pd4.); put y $hex8.;
Kurt_Bremser
Super User

@BrahmanandaRao wrote:
PDw.d Format y=put(x,pd4.); put y $hex8.;

You got your leading zeroes there, already?

 

What are you really trying to accomplish that my code example does not provide?

Patrick
Opal | Level 21

@Kurt_Bremser 

Bit harsh of a comment directed at a a newbie. 

 

@BrahmanandaRao 

It would help all of us if you add a bit more explanation to your posts - like what you have, what you need, what you've tried already and got stuck.

BrahmanandaRao
Lapis Lazuli | Level 10

USING PDW.D function 

i want to add leading zero in the above code

 

Thank You

ANAND

Patrick
Opal | Level 21

@BrahmanandaRao 

 

FUNCTION

There is no PDW function in SAS. The available SAS functions are documented here:

http://support.sas.com/documentation/cdl//en/lefunctionsref/69762/HTML/default/viewer.htm#p0w6napahk... 

 

Functions "do" something and then return a value. In SAS syntax functions are used right of a equal sign and have a form of FUNCTION().

 

FORMAT

There is a PD format in SAS - documented using SAS standards as PDw.d - where w and d are placeholders for digits.

Formats are documented here:

https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#p0z62k899n6...

Formats change the way SAS writes (prints) a value. Writing packed decimals is quite unusual and though likely something you don't need to do.

There is another SAS format which lets you instruct to add leading zero's to a number. This is the Zw. format - also documented under above link.

You can assign a format permanently a to variable so that when you print the values in the variable these values get printed formatted. 

To do so you would use a SAS datastep STATEMENT like: FORMAT myvar z10.

 

You can also use the put() FUNCTION to apply a FORMAT to a VARIABLE and then assign this formatted value to another variable.

new_var=put(myvar,z10.)

 

How these things work and explanations what statements, functions, formats etc. are is part of basic SAS training - some free and online available. It appears these are things which still confuse you a bit and I guess that's what triggered some comments. You'll get there! 

BrahmanandaRao
Lapis Lazuli | Level 10

Thank you sir

 

for your valuable suggetion

 

 

Regards,

anand

ballardw
Super User

@BrahmanandaRao wrote:
data ds;
input id;
y=(X ,pd4.);
cards;
'1234'

;
run;

Result

 

00001234


Yields:

5    data ds;
6    input id;
7    y=(X ,pd4.);
          -
          388
          200
          76
ERROR 388-185: Expecting an arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 76-322: Syntax error, statement will be ignored.

8    cards;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set USER.DS may be incomplete.  When this step was stopped there were 0
         observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.00 seconds

11   ;

So what was

 

y=(X ,pd4.);

supposed to do?

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 8 replies
  • 1717 views
  • 1 like
  • 4 in conversation