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
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.
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.
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.
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.
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.