BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ammarhm
Lapis Lazuli | Level 10

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


1 ACCEPTED SOLUTION

Accepted Solutions
gergely_batho
SAS Employee

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.

View solution in original post

2 REPLIES 2
gergely_batho
SAS Employee

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.

Reeza
Super User

Remove the compress to see what it's doing Smiley Happy

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1278 views
  • 3 likes
  • 3 in conversation