## Help deciphering this code

Solved
Regular Contributor
Posts: 182

# Help deciphering this code

Hi all

A short question

I am working through a code that I am trying to understand and modify

here is the code

proc sql;

select distinct Var1,

compress(put(sum(Var2),comma7.) ||"/"|| put(sum(Var3),comma12.))

from x

group by Var1;

quit;

Could anyone please explain in simple wording what this code is doing, with focus on the compress() part?

Happy New Year to the SAS community

Accepted Solutions
Solution
‎12-30-2014 04:48 PM
SAS Employee
Posts: 340

## Re: Help deciphering this code

distinct is not needed here

We aggregate (take the sum) of Var2 and Var3. We convert both numbers to character strings with the commaW. format, then we concatenate those 2 character strings but also place a "/" between them.

We use the compress function to remove blanks from this concatenated string. For example converting a number to string with the comma12. format can result in a sting: "       123,4". We need to remove the extra blanks.

So the end result is: to summary numbers separated with a slash.

All Replies
Solution
‎12-30-2014 04:48 PM
SAS Employee
Posts: 340

## Re: Help deciphering this code

distinct is not needed here

We aggregate (take the sum) of Var2 and Var3. We convert both numbers to character strings with the commaW. format, then we concatenate those 2 character strings but also place a "/" between them.

We use the compress function to remove blanks from this concatenated string. For example converting a number to string with the comma12. format can result in a sting: "       123,4". We need to remove the extra blanks.

So the end result is: to summary numbers separated with a slash.

Super User
Posts: 23,724

## Re: Help deciphering this code

Remove the compress to see what it's doing

Hint: Spaces, RTM

The code is taking the sum of var2, formatted to comma7 concatenating it to the sum of var3 formatted to comma12, separated by a slash.

🔒 This topic is solved and locked.