Hello
I know that in proc sql there are rules of order of operations:
From---Where-----Select
So in this case first go to data set "Have"
Then perform row filter (obs=1) so it take only first row
Then it perform the select activities.
My question:
Since we asked to take only one row,
then how the operations in select that working on all observations will work?
select 'TOTAL' as Category,
(select count(*) as nr_customers from have),
1 as PCT_Customers,
(select sum(wealth) as Sum_Wealth from have),
1 as Pct_Wealth
from have(obs=1);
quit;
Because the summations are done in the sub-selects, where all observations are read.
Because the summations are done in the sub-selects, where all observations are read.
How about describing what you are attempting to do with example data?
Or try removing the (OBS=1) and see the result. In this case I am pretty sure that the given code will yield NN number of identical records where NN is the number of observations in the data set.
SQL does not have any standard order of using records so I am not sure what you are asking about in this case.
Your code
(select count(*) as nr_customers from have)
Will not create a variable nr_customers but a generated name like _TEMA002. If you want the result to be named nr_customers the syntax is
(select count(*) from have) as nr_customers
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.