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 Employee

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;

 

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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