BookmarkSubscribeRSS Feed
Midi
Obsidian | Level 7

Hello Everyone , I Have This Block of code that i'm trying to run :

 

Proc Sql;
Create Table Work.Tbl_Dt_Tip_Count As
      Select
            Prep.Date
          , Prep.Name
          , Count(distinct Code || name || put(Year, 8.)) As Count
	  From
	     (
		    Select 
			      A.Date
			    , B.Name
				, B.Code
				, B.Year
		 From 
	          Work.Want_Day A
 	  Left join
	          Ext_Data.Tbl_Date B
          
		  on  Date >= min(dt_start)
		  and Date <= Max(Dt_end)
   ) Prep
      Group by

            Date
          , Name
Quit;

but i ran onto this error :

Summary functions are restricted to the SELECT and HAVING clauses only.

 

any help would be much appreciated , thank u

2 REPLIES 2
Krueger
Pyrite | Level 9

Does this run without error? 

 

If so you may have to break this out into two datasets and then do your count.

 

Proc Sql;
Create Table Work.Tbl_Dt_Tip_Count As
      Select
            Prep.Date
          , Prep.Name
	  From
	     (
		    Select 
			      A.Date
			    , B.Name
				, B.Code
				, B.Year
		 From 
	          Work.Want_Day A
 	  Left join
	          Ext_Data.Tbl_Date B
          
		  on  Date >= min(dt_start)
		  and Date <= Max(Dt_end)
   ) Prep
      Group by

            Date
          , Name
Quit;
novinosrin
Tourmaline | Level 20

If I understand correctly, I am afraid summary functions are not permitted in an on clause, and so this complicates to further nest like 

 



Proc Sql;
Create Table Work.Tbl_Dt_Tip_Count(drop=min max) As
      Select
            Prep.Date
          , Prep.Name
          , Count(distinct Code || name || put(Year, 8.)) As Count
	  From
	     (
		    Select 
			      A.Date
			    , B.Name
				, B.Code
				, B.Year
		 From 
	          Work.Want_Day A
 	  Left join
	          (select *,min(dt_start) as min, max(Dt_end) as max) B
          
		  on   min<=Date<=max
		 
   ) Prep
      Group by

            Date
          , Name;
Quit;
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
  • 1478 views
  • 1 like
  • 3 in conversation