BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5

I am doing like this. data l2; input id no; cards; 1 100 2 200 3 300 run; proc sql; select count(max(no)) into :l2 from l2 where id=3; quit; i am getting this ERROR ERROR: Summary functions nested in this way are not supported. i want the output that macro L2 should have count as 1.

6 REPLIES 6
R_Win
Calcite | Level 5

For your Ref

manojinpec
Obsidian | Level 7

You might need to use having keyword for condition of summary variables.

Ksharp
Super User

If I have understood what you mean.

data l2;
input id no;
cards;
1 100
2 200
3 300
run;

proc sql;
select count(*) into :l2 from l2 where id=3 having no=max(no);
quit;

%put &l2;

Ksharp

R_Win
Calcite | Level 5

small probelm data l2; input id no; cards; 1 100 2 200 3 300 3 400 run; proc sql; select count(*) into :l2 from l2 where id=3 having no=max(no); quit; %put &l2; But i want the count id =3 and no having max count here the max(no)=400 so i should get count as 1 but it was getting output as 2.

shshiva
Calcite | Level 5

Hi,

Try this...Hope it helps..

proc sql;

select count(id) as count into :s2 from l2 where id =(select max(id) from l2);

quit;

Thanks,

Shiva

Ksharp
Super User

It is very intesting . I don't realize it will appear so weird result. Try it.

data l2; 
input id no; 
cards; 
1 100 
2 200 
3 300 
3 400 
;
run; 
proc sql; 
select count(*)  into :l2 
 from (select *  from l2 group by id having id=3 and no=max(no) )
 ; 
quit;
%put &l2;

Ksharp

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 6 replies
  • 1672 views
  • 0 likes
  • 4 in conversation