Hi ,
I have a variable DATE_E1 which is in date format and value is 20170410 or 2020007. I need to print this value exactly as 10-Apr-17 or 7-Feb-20 .
Can you please help me with the code
Thanks
Hi ,
I tried but getting ERROR printed in output. Please let me know why
data a;
input date;
cards;
20201210
20170517
;
run;
proc format;
picture mydate
low-high='%j-%3B-%y' (datatype=date);
run;
proc print data=a;
format date mydate.;
run;
Output :
Obs | date |
1 | ERROR |
2 | ERROR |
@ss171 wrote:
Hi ,
I tried but getting ERROR printed in output. Please let me know why
data a; input date; cards; 20201210 20170517 ; run; proc format; picture mydate low-high='%j-%3B-%y' (datatype=date); run; proc print data=a; format date mydate.; run;
Output :
Obs date 1 ERROR 2 ERROR
Your dates in data set named A are not recognized by SAS as an actual date. SAS dates are integers that represent the number of days since 01JAN1960. Your dates are integers, but only recognizable by humans as actual dates, not by SAS. This is a crucial point if you are going to be using SAS dates.
To make these dates recognizable by SAS, use an informat :YYMMDD8. in the INPUT statement. (or you can use the INPUT function)
proc format;
picture mydate low-high='%d-%3B-%y' (datatype=date);
run;
data a;
input date :yymmdd8.;
format date mydate.;
cards;
20201210
20170517
;
Also please note that %y in the picture format must be lower case
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.