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
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;
I attempted a case when but unfortunately experienced the same issue.
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
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.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.