BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
me55
Quartz | Level 8

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?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@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.

 

View solution in original post

4 REPLIES 4
ballardw
Super User

@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
Quartz | Level 8

perfect...the quotes worked great to leave that leading zero on there.  thanks for the explanation, it helps me understand the underlying issue considerably!

Tom
Super User Tom
Super User

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.

me55
Quartz | Level 8
yeah i realize all of that stuff. i have no choice on that. i am rebuilding something not building it on my own.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 3130 views
  • 2 likes
  • 3 in conversation