BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Onyx | Level 15

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;

 

 

1 ACCEPTED SOLUTION
2 REPLIES 2
ballardw
Super User

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

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 952 views
  • 4 likes
  • 3 in conversation