BookmarkSubscribeRSS Feed
dlazer1
Calcite | Level 5

Below is the code I have but I am getting no observations once I do this step. Please help!

 

data workingdata;
set work.test;
Format CIK $10;

IF COMPANY_FKEY<=9999 THEN CIK =cats('000000',COMPANY_FKEY);

 

I need to create all these values as 10 digits with leading 0's. 

Do I need to define company_fkey before?

 

Thank you!

5 REPLIES 5
JasonDiVirgilio
Quartz | Level 8

Make sure there is a period ('.') after your format... so it should look like FORMAT CIK $10.;

 

And yes, the variable COMPANY_FKEY needs to be defined in the work.test dataset  if you are going to test its value in the workingdata data step.

dlazer1
Calcite | Level 5

data workingdata;
267 Set work.test;
268 COMPANY_FKEY=CIK;
269 run;

 

271 data workingdata1;
272 Set work.workingdata;
273 Format CIK $10.;
WARNING: Variable CIK has already been defined as numeric.

 

This now shows up. How do I orignally format CIK as numeric---need it to be character since I need the leading zeros. Numeric gets rid of the leading zeros. 

ballardw
Super User

@dlazer1 wrote:

data workingdata;
267 Set work.test;
268 COMPANY_FKEY=CIK; Since CIK already exists here it seems that it was created or made numeric when work.test was created.
269 run;

 

271 data workingdata1;
272 Set work.workingdata;
273 Format CIK $10.;
WARNING: Variable CIK has already been defined as numeric.

 

This now shows up. How do I orignally format CIK as numeric---need it to be character since I need the leading zeros. Numeric gets rid of the leading zeros. 


If you have a numeric variable and need to create a character version then use

Charversion = put(numericversion, Z10.);

the Z format pads the displayed value with leading zeroes to the number of spaces indicated in the format. If the variable has a value of 123 and you use the Z10 it will display, or with put statement as shown create, 0000000123

dlazer1
Calcite | Level 5

Thank you!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 1416 views
  • 0 likes
  • 4 in conversation