The internal storage of a value in a variable of type Numeric will never have leading zero's - but you can always attach a format permanently to the variable as shown above.
The other option is to save the digits as a string in a new variable of type Character as shown below:
sch_date_c=put(SCH_DATE, z6.);
If this is just about how a numerical value displays/prints then you can use format Zw.d
format SCH_DATE z6.;
The internal storage of a value in a variable of type Numeric will never have leading zero's - but you can always attach a format permanently to the variable as shown above.
The other option is to save the digits as a string in a new variable of type Character as shown below:
sch_date_c=put(SCH_DATE, z6.);
I believe you should go for the approach @Kurt_Bremser proposed and convert your data to a SAS Date value as this will allow you to actually work with this data as dates - like calculating the number of days between two dates.
When values reflect dates, they have to be stored as dates:
length sch_date_new 4;
sch_date_new = input(put(sch_date,z6.),mmddyy6.);
format sch_date_new yymmddd10.;
Because of the sheer stupidity of still using 2-digit years after Y2K, you will have to adjust the YEARCUTOFF option value.
I've totally missed that these values represent dates. Definitely use what @Kurt_Bremser proposes and convert these numbers into SAS Date values. This then allows you to actually use SAS calendar functions like intnx() and intck().
Thank you! More than one of the options worked. Appreciate the help!
You don't have to use the length statement, especially if your data set is compressed, but @Kurt_Bremser reply is the only way to go: store a date as a date.
I prefer to use the length statement because compressing a lot of essentially nothing (hex 00's) still needs more space than not having those bytes in the first place. It's not much, but this old coder hates wasting space and CPU cycles.
@Kurt_Bremser I used to do this, but most users would not do it, and I got tired of length-mismatch messages for a small benefit as long as the table is compressed. No right or wrong of course.
I do have the benefit of a tightly knitted environment when it comes to data sources. 99% originates from DB/2 or SAP, and is imported by centrally controlled (read: me and two others <g>) processes/programs. We have a macro defined for importing columns with types (char/date/datetime/time/packed decimal/zoned/UUID, even binary), so the length of a date is actually set in one include for all data we have.
Only when end users import their own data, they can have length issues, but that happens usually only once per user, then they know.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.