i have a field i created...
proc sql NOPRINT;
CREATE TABLE TABLE (
...
FILEDATE char(8),
...);
quit;
then i filled that field...
data _null_;
eom=put(intnx('month',today(),-1,'E'),mmddyy6.);
call symput('efiledt',eom);
run;
data TABLE;
set TABLE;
FILEDATE=&efiledt;
run;
okay, so my problem is that sas keeps dropping the leading zero and i need that leading zero to stay. i tried formatting...
data TABLE;
set TABLE;
FILEDATE=put(FILEDATE,z6.);
run;
but it did not like that...kept giving me a unknown format z error. i thought that should be a character thus keeping that leading zero however that is not working. how can i adjust this to leave that leading zero on?
@me55 wrote:
i have a field i created...
proc sql NOPRINT;
CREATE TABLE TABLE (
...
FILEDATE char(8),
...);
quit;
then i filled that field...
data _null_;
eom=put(intnx('month',today(),-1,'E'),mmddyy6.);
call symput('efiledt',eom);
run;
data TABLE;
set TABLE;
FILEDATE=&efiledt;
run;
okay, so my problem is that sas keeps dropping the leading zero and i need that leading zero to stay. i tried formatting...
data TABLE;
set TABLE;
FILEDATE=put(FILEDATE,z6.);
run;
but it did not like that...kept giving me a unknown format z error. i thought that should be a character thus keeping that leading zero however that is not working. how can i adjust this to leave that leading zero on?
Since you are using an implicit numeric to character in
FILEDATE=&efiledt;
that will happen because SAS does not have "leading zeroes" on numeric values.
What you seem to want would be
FILEDATE="&efiledt.";
So that the macro value is treated as a character value.
The error message you were getting is because since FILEDATE is character variable it expects any formats used with it, such as in PUT to be $defined variables. SAS tried to find a $Z format but there is not one by default. Zw.d is format for numeric values.
You could have used
Filedate= put(&efiledt. , z6.);
but still awkward code.
@me55 wrote:
i have a field i created...
proc sql NOPRINT;
CREATE TABLE TABLE (
...
FILEDATE char(8),
...);
quit;
then i filled that field...
data _null_;
eom=put(intnx('month',today(),-1,'E'),mmddyy6.);
call symput('efiledt',eom);
run;
data TABLE;
set TABLE;
FILEDATE=&efiledt;
run;
okay, so my problem is that sas keeps dropping the leading zero and i need that leading zero to stay. i tried formatting...
data TABLE;
set TABLE;
FILEDATE=put(FILEDATE,z6.);
run;
but it did not like that...kept giving me a unknown format z error. i thought that should be a character thus keeping that leading zero however that is not working. how can i adjust this to leave that leading zero on?
Since you are using an implicit numeric to character in
FILEDATE=&efiledt;
that will happen because SAS does not have "leading zeroes" on numeric values.
What you seem to want would be
FILEDATE="&efiledt.";
So that the macro value is treated as a character value.
The error message you were getting is because since FILEDATE is character variable it expects any formats used with it, such as in PUT to be $defined variables. SAS tried to find a $Z format but there is not one by default. Zw.d is format for numeric values.
You could have used
Filedate= put(&efiledt. , z6.);
but still awkward code.
perfect...the quotes worked great to leave that leading zero on there. thanks for the explanation, it helps me understand the underlying issue considerably!
Some more things to think about for this type of issue.
Leading zeros on numbers do not change the value stored.
It looks like you are storing dates into character variables. In that case I would recommend storing them using Year, Month, Day order so that when you sort in lexical order the values will also be in chronological order.
Also you need to use four digits for the year. My grandfather was born 98 and my son in 99 but they were born more than one year apart.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.