Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compress function 1

Status
Not open for further replies.

liliya13

Technical User
Aug 5, 2004
44
US
Hi Everybody,

Could you please tell me what Compress function does?
For ex

Yearmonthend=compress(YearE) ||'/'||compress(monthasked);

Thank you in advance,

Liliya
 
This function takes out any char that you supply with the function. By default (without any char params) it takes the blank spaces out of a string.

Ex.
x = "there was once a fox";
y= compress(x);

The value in 'y' will now have "therewasonceafox". You should check out the SAS help online at username: sas
pw: docs4

I hope that this helps you.
Klaz
 
in your example compress will create the text string "YearE/monthasked". Assuming that "YearE" and "monthasked" are numeric it convert them and suppress any space characters that might be included in the conversion. Without the compress function you might get something like " YearE"/" monthasked".

I often use compress in just this fashion to convert text to numeric.

I hope this helps.

** mp **
 
One thing to note. SAS is quite forgiving about doing this sort of thing (using a character function on a numeric field) and will just convert the numeric to a char. However, if you start using Enterprise Guide, you'll have to be alot more careful, it doesn't seem to do that anymore and will actually give an error message along the lines of "invalid type for argument to character function COMPRESS" or something like that. You have to learn to use your PUT() and INPUT() functions then to convert your variables.
Just a word of warning.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top