Hi, I am importing an excel spreadhseet with around 5000 mortgage numbers. Some numbers are only 7 numbers in length so for those accounts I need to add a leading zero. The code used below, any idea why I get the error message here please?
17 mortgage=put(_mortgage,z10.);
____
484
NOTE 484-185: Format $Z was not found or could not be loaded.
CODE WRITTEN BELOW
data MIRA_RED_ACCOUNTS_2016;
infile "/opt/sas/data/uk/Personal Folders/Scants/MIRA Red Accounts2016.csv";
input mortgage : $10.;
run;
data mira;
set WORK.MIRA_RED_ACCOUNTS_2016 (rename=(mortgage=_mortgage));
mortgage=put(_mortgage,z10.);
run;
The Z. format only works with numeric fields so you first have to convert it. e.g.:
data MIRA_RED_ACCOUNTS_2016; input mortgage : $10.; cards; 123 4567 ; data mira; set WORK.MIRA_RED_ACCOUNTS_2016 (rename=(mortgage=_mortgage)); mortgage=put(input(_mortgage,10.),z10.); run;
Art, CEO, AnalystFinder.com
You have one dollar sign too many:
input mortgage : $10.;
Get rid of the dollar sign to create MORTGAGE originally as a numeric variable. Your final DATA step will convert it to character.
if I remove the $ from input mortgage : $10.; then all I see is a dot for my mortgage?
If you are getting . for the mortgage values, it indicates that there are other characters (non-numeric) present. To overcome that, leave the $ in place and try:
len = length(mortgage);
if len < 10 then mortgage = repeat('0', 9-len) || mortgage;
Consider using an ATTRIB statement:
data MIRA_RED_ACCOUNTS_2016;
attrib mortgage format=z10. ;
input mortgage : 10.;
cards;
123
4567
;
run;
I rarely have a data step w/o an attrib. Define the variables for the data step before creating them so your final dataset is exactly as you want.
Given the problem you are confronting It would help if you attach a representative sample dataset.
Art, CEO, AnalystFinder.com
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.
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.