BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8

what would compressing a date give me? just removing any space around?

my command is as follows:

compress(put(intnx('month',"&perfdate."d,0,'end'),monyy6.))

4 REPLIES 4
SASKiwi
PROC Star

Have you tried it both with and without? The COMPRESS function should not make any difference here.

 

BTW, when you post code questions, please post complete statements and preferably program steps. Also use the "Insert SAS Code" menu option.

HeatherNewton
Quartz | Level 8
on never see the "insert SAS code", where is it, will use going forwards

you mean it is not removing the space or you mean even if the space is removed, it makes no diff to the end result
Kurt_Bremser
Super User

The indicated button has to be used for logs and textual data where it is necessary that the horizontal spacing is kept and no characters are changed. The "little running man" right next to it is meant for posting SAS code, as it additionally provides coloring similar to the SAS Enhanced Editor.

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

Tom
Super User Tom
Super User

Dates are numbers.  COMPRESS() works on character strings.

So to use COMPRESS() with a date value you would first need to convert it into a string.  

Your code is using the PUT() function to convert date value generated by the INTNX() function into a character string using the display format specification of MONYY6.   Since that will use 3 positions for the month abbreviation that leaves only 3 positions for the year.  SAS will truncate the year to just the last two digits by eliminate the century part.  This yield only 5 characters which will be right align in the 6 character string that is generated.

You didn't tell COMPRESS() what characters to compress out of the string, so it will default to removing the spaces.  Thus the leading space will be removed.

 

You could eliminate the need for the COMPRESS() function by using MONYY5. format instead of MONYY6. since then there would be no leading space.  Or better still use the MONYY7. format and you will have room for all four digits of the year and you still wouldn't have any leading spaces.

 

PS: Learn what the buttons on the tool bar that appears above the text box of the forum editor do.

Screenshot 2022-03-03 215400.jpg

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1335 views
  • 1 like
  • 4 in conversation