BookmarkSubscribeRSS Feed
joshkylepearce
Calcite | Level 5

Hi everyone, 

 

I'd like to count the number of visits to a branch a bank receives per day, which are open from Monday-Saturday. I've attached an excel spreadsheet with my exported results, which shows a number of visits per day from Monday-Saturday. 

 

Basically what I'd like to achieve is rather than a missing volume and date each Sunday, I'd like to output a volume of zero and the particular date each week. 

 

The simple code I used to produce the output is as follows:

proc sql;
create table Work.Footfall2 as
select
Volumes,
TransactionDate
from
Work.Footfall
group by
TransactionDate
;
quit;

 

Any ideas/suggestions would be greatly appreciated. 

 

Thanks, 

 

Josh

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sorry not going to be downloading Excel files.  Also, use the code window - its the {I} above post area - for code.  Not sure what your SQL is trying to achieve, you have a group by with no aggregate functions (like sum() or count()).  You can use a case when anyways, maybe:

proc sql;
  create table Work.Footfall2 as
  select case when sum(VOLUMES)=. then 0 else sum(VOLUMES) end as VOLUMES,
         TRANSACTION_DATE
  from   WORK.FOOTFALL
  group by TRANSACTIONS_DATE;
quit;
joshkylepearce
Calcite | Level 5

I attempted a case when but unfortunately experienced the same issue. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

So post some test data in the form of a datastep, so we can run something.  I can't debug something I can't see Smiley Happy

ballardw
Super User

If your dates are actually SAS date values then you could exclude Sundays from the result with a where clause like

 

where weekday(transactiondate) ne 1

 

Also not going to download Excel files.

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

antonbcristina
SAS Super FREQ

Your best bet is to create a data set that has all dates in a particular range, including the Sundays as well. 

data alldates;
   do TransactionDate='01Jan2014'd to '06Jan2014'd;
       output;
   end;   
run;

 Then join it with your aggregated data , setting volumes=0 for the missing Sundays.

proc sql;
   create table footfall3 as
   select b.TransactionDate format=date9., coalesce(a.volumes,0) as volumes
   from footfall2 as a right join alldates as b
   on a.TransactionDate=b.TransactionDate;
quit;

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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