03-06-2013 03:54 PM
I have a variable date called mydate
format mydate mmddyy10.;
sample output 03/04/2013
I want to supress the month and day if there is a leading zero
03-06-2013 04:49 PM
Another way of doing it,
input dt MMDDYY10. ;
03-06-2013 04:52 PM
have a look at the PICTURE statement of the FORMAT procedure.
That allows you to define the layout of your choice. The month and day can be defined to appear without a leading zero.
The link is to the PICTURE statement http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/p0n990vq8gxca6n1vnsracr6jp2c.htm
once there look down the webpage until you find the directives
I think you will want something like
picture mydate low-high = '%m/%d/%Y'( datatype= date) ;
%put %sysfunc( today(), mydate ) ;
stringdate = put( sas_date, mydate10. ) ;
but first read the doc and see what examples it provides
03-07-2013 06:35 PM
here is the user format approach, to work in any context
37 proc format ;
38 picture mydate low-high = '%m/%d/%Y'( datatype= date) ;
NOTE: Format MYDATE has been output.
NOTE: PROCEDURE FORMAT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
41 data new;
42 informat mydate mmddyy10.;
43 input mydate ;
44 format mydate mydate.;
45 put mydate= date9. mydate= ;
NOTE: The data set WORK.NEW has 5
11-05-2017 03:52 PM - edited 11-05-2017 03:53 PM
The Picture Format works very well, and it leaves the data as a SAS date for functions and calculations. Just don't forget to add the 10 when you use it or your dates will drop the last few digits. The digits get dropped from right so 11/11/2011 may become 11/11/20 on output if you do not set the length to 10.
03-08-2013 01:27 PM
CATX is used for removing trailing and leading spaces as well as to insert DELIMITERS....
But in this case it is removing leading ZEROS....
So my question is :
IS ZERO considered LEADING OR TRAILING SPACE???????
03-08-2013 01:54 PM
catx is silently converting the numbers to strings. It is not adding any leading zeros. So numbers less than 10 will be only one digit.
The zeros are never generated, so CATX() is not removing any zeros.
03-08-2013 02:08 PM
Consider this little program.
Note that even if tell SAS that Y should be displayed with leading zeros when CATX() still converts without using the Z format.
Note that C which is a character variable and hence does not undergo any conversion keeps all of its characters.
x=1 ; y=2; c=' 09' ;
format y z3.;
put (_all_) (=);
x=1 y=002 c=09 s=1/2/09
03-08-2013 02:29 PM
If I am not wrong........
if a numeric value of 000900 in SAS is converted to char value using CATX.....its value will be '900'
05/09/2009 is converted to 5/9/2009. if it was 09 instead of 2009 then is this correct???
05/09/09 is converted to 5/9/9
03-08-2013 02:41 PM
To understand what the CATX() function is doing do not think about it is dates. Also there is no such thing as a numeric value of 000900, at least not one that is different than 900 or any other way of expressing the number nine hundred ( 9*100, 1000-100, '384'x etc.). So in this statement
CATX is operating on three numbers. They happen to be a month, a day and a year, but CATX() doesn't know that (or care).
So if DATE='09MAY2009'd then CATX receives the numbers 5,9 and 2009.
It converts them to the strings '5','9', and '2009'.
Then it sticks slashes between them to generate the final string '5/9/2009'.