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.
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!
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.
Ready to level-up your skills? Choose your own adventure.