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!
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.
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.
You can't change the type of the variable, you can only replace it by creating a new variable and using rename= and drop= dataset options.
@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
Thank you!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.