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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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