BookmarkSubscribeRSS Feed
ss171
Calcite | Level 5

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 

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

You need to write your own picture format.

Use:

%j for the day

%3B for the month

%y for the year 

 

ss171
Calcite | Level 5

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 :  

Obsdate
1ERROR
2ERROR

 

 

PaigeMiller
Diamond | Level 26

@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

--
Paige Miller
ss171
Calcite | Level 5
Thanks for your help

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1084 views
  • 1 like
  • 3 in conversation