DATA Step, Macro, Functions and more

formats

Reply
Contributor
Posts: 45

formats

Add leading zero to numeric variable WithOUT using ZW.D format

Super User
Posts: 9,586

Re: formats

Posted in reply to shivamarrora0

shivamarrora0 wrote:

Add leading zero to numeric variable WithOUT using ZW.D format


Why would somebody want to do such a stupid thing? Use the right tool (Maxim 14).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 45

Re: formats

Posted in reply to KurtBremser
This was the question asked by me in an interview
Super User
Posts: 9,586

Re: formats

Posted in reply to shivamarrora0

My answer would be

"You want me to do meaningful work for you, not waste my (and your) time, don't you?"

 

Look for an employer with brains.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 13,046

Re: formats

Posted in reply to shivamarrora0

shivamarrora0 wrote:
This was the question asked by me in an interview

Generally when given an abitrary restriction in a question like that I would ask questions about any cause for the restriction. Such restrictions might arise based on something else in the data/procedures/environment limits and a suggestion should tailor to the causes.

 

Other wise this is like asking someone to add without using + button on a calculator.

Super User
Super User
Posts: 9,211

Re: formats

Posted in reply to shivamarrora0

Whilst I completely agree with @KurtBremser that this is typical daft interview question, it is designed to see how you think on your feet (i.e. you wouldn't know this was a question coming up).  It would also demonstrate if you know multiple ways of doing things.  Couple of options:

1) Create your own picture format and apply

2) Create a text version of the number and use string functions to add the required number of zeroes

 

Obviously the ideal scenario is to keep as a number and format using the provided Z format, however knowing the other options can be useful in other scenarios, such as if the format doesn't show exactly the way you want it to.

Super User
Posts: 10,615

Re: formats

Posted in reply to shivamarrora0



proc format;
picture fmt
 other='999999';
run;
data a;
 set sashelp.class;
 keep age;
 format age fmt6.;
run;

Ask a Question
Discussion stats
  • 6 replies
  • 168 views
  • 5 likes
  • 5 in conversation