BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello, I'm trying to create a date stamp in SAS from an inputted variable, but I'm having a problem when truncating year from 4 digits to 2 digits. SAS is dropping the leading zero.

For example;

month = 01
day = 15
year = 2009

Trying to create the date stamp it currently appears as 1159 instead of 011509 (which is what is needed).

If I need to supply more information, please let me know. Any help would be greatly appreciated.
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Suggest you share the code that generates the SAS variable - the reason is because you have not identified what output format you are using, nor whether you are already converting a SAS "numeric type" DATE variable to character, by using a PUT function.

Suggest also having a look at the PROC FORMAT documentation and particularly the use of a "custom date format" with PICTURE.

Scott Barry
SBBWorks, Inc.

SAS Procedures Guide, PICTURE Statement
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a002473467.htm
DanielSantos
Barite | Level 11
You are probably converting numerics to alphas without specifying a leading zero format.
[pre]
data _null_;

DT='15JAN2009'd;

* explicit conversion, no leading zero format;
M=put(month(DT),2.);
D=put(day(DT),2.);
Y=put(mod(year(DT),100),2.);
X=cats(M,D,Y);
put _all_; * wrong;

* implicit conversion, no format at all;
M=month(DT);
D=day(DT);
Y=mod(year(DT),100);
X=cats(M,D,Y);
put _all_; * wrong;

* explicit conversion, with leading zero format;
M=put(month(DT),z2.);
D=put(day(DT),z2.);
Y=put(mod(year(DT),100),z2.);
X=cats(M,D,Y);
put _all_; * right!;

run;
[/pre]
But, that's only an assumption.

Help us to help you. As said above, you should always share you're code.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
data_null__
Jade | Level 19
"always" convert date data to SAS/Date. Then you can display with any format. The one you want is built in.
[pre]
359 data _null_;
360
361 month = 01;
362 day = 15;
363 year = 2009;
364
365 date = mdy(month,day,year);
366
367 put 'STAMP: ' date mmddyyN6.;
368 run;

STAMP: 011509
[/pre] Message was edited by: data _null_;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 909 views
  • 0 likes
  • 4 in conversation