BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MART1
Quartz | Level 8

Hello

 

I'm trying to return the Date field in lower case, but only the day and month - so in the below example I'd like to see 01 Jan, 02 Jan etc..

 

data Test;
	input Day Vol;
	datalines;
20200101    685.47
20200102    734.91
20200103    726.01
20200104    767.21
20200104    891.71
;
run;

PROC SQL;
	CREATE TABLE TEST1 AS 
		SELECT Input( Put( Day, 8.), yymmdd8.) FORMAT=DATE5. AS Day, Vol
			FROM TEST;
QUIT;

I've tried all the options with WORDDATX, WORDDATE but I can't find the way to only show day and month.

 

(of course LOWCASE is not an option as it's not a Char)

 

thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

One way to get something like this:

PROC SQL;
	CREATE TABLE TEST1 AS 
		SELECT lowcase(substr(put(Input( Put( Day, 8.), yymmdd8.),date9.),1,5)), Vol
			FROM TEST;
QUIT;

You can create a custom format that would show just day of month and the month name. However the result will still have the month either upper case or proper case such as "Jan" . The result you showed is not actually lower case. Did you mean Proper case with the initial letter capital? And do you actually need a space between the day and the month?

proc format;
 picture dm
 low-high ='%0d %3B' (datatype=date)
 ;
run;

PROC SQL;
	CREATE TABLE TEST1 AS 
		SELECT Input( Put( Day, 8.), yymmdd8.) as day format= dm., Vol
			FROM TEST;
QUIT;

View solution in original post

3 REPLIES 3
ballardw
Super User

One way to get something like this:

PROC SQL;
	CREATE TABLE TEST1 AS 
		SELECT lowcase(substr(put(Input( Put( Day, 8.), yymmdd8.),date9.),1,5)), Vol
			FROM TEST;
QUIT;

You can create a custom format that would show just day of month and the month name. However the result will still have the month either upper case or proper case such as "Jan" . The result you showed is not actually lower case. Did you mean Proper case with the initial letter capital? And do you actually need a space between the day and the month?

proc format;
 picture dm
 low-high ='%0d %3B' (datatype=date)
 ;
run;

PROC SQL;
	CREATE TABLE TEST1 AS 
		SELECT Input( Put( Day, 8.), yymmdd8.) as day format= dm., Vol
			FROM TEST;
QUIT;
MART1
Quartz | Level 8

Hi @ballardw 

 

Thank you so much, this is exactly what I needed! - and you are right, I didn't explain it really well.

 

ps: I've very little knowledge of proc format; could you explain what    '%0d %3B'   mean?

 

(I'm pushing my luck here, but is there any chance it can be displayed as ,i.e. 1st Jan, 2nd Jan... ?)

 

once again thank you very much

 

 

ballardw
Super User

@MART1 wrote:

Hi @ballardw 

 

Thank you so much, this is exactly what I needed! - and you are right, I didn't explain it really well.

 

ps: I've very little knowledge of proc format; could you explain what    '%0d %3B'   mean?

 

(I'm pushing my luck here, but is there any chance it can be displayed as ,i.e. 1st Jan, 2nd Jan... ?)

 

once again thank you very much

 

 


The PICTURE statement for Proc format has directives to build custom date, time or datetime formats. Read the documentation and is pretty clear. The % starts the directive, the 0 says to preface single digits with a zero, the lower case d is days (these directives are very case sensitive) a space before the next directive, the 3 says how many letters of the proper case month name indicated by B.

 

Please be aware this is one of the few places that you pretty much must use single quotes. If you use double quotes around these directives SAS will complain about macro issues because of the % characters.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 2400 views
  • 1 like
  • 2 in conversation