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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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