data ds;
input id;
y=(X ,pd4.);
cards;
'1234'
;
run;
Result
00001234
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 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?
Bit harsh of a comment directed at a a newbie.
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.
USING PDW.D function
i want to add leading zero in the above code
Thank You
ANAND
FUNCTION
There is no PDW function in SAS. The available SAS functions are documented here:
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:
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!
Thank you sir
for your valuable suggetion
Regards,
anand
@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?
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!
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.
Ready to level-up your skills? Choose your own adventure.