BookmarkSubscribeRSS Feed
shivamarrora0
Obsidian | Level 7

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

9 REPLIES 9
Kurt_Bremser
Super User

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

shivamarrora0
Obsidian | Level 7
This was the question asked by me in an interview
Kurt_Bremser
Super User

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.

ballardw
Super User

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

Ranjeeta
Pyrite | Level 9

data NACRS.NACRS1617;
704 set NACRS.NACRS1617(rename=(RESPONSIBILITY_FOR_PAYMENT=temp));
705 RESPONSIBILITY_FOR_PAYMENT = put(temp,Z2.);
---
48
ERROR 48-59: The format $Z was not found or could not be loaded.

706 run;

 

Am I writing this correctly?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Whilst I completely agree with @Kurt_Bremser 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.

Ksharp
Super User



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

Tom
Super User Tom
Super User

I do not understand that question.

 

You cannot add a lead zero to a number.  Or put another way no matter how many leading zeros you add to a number it won't change the value of the number.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 9 replies
  • 1427 views
  • 5 likes
  • 7 in conversation