Desktop productivity for business analysts and programmers

Assigning a zero to blank entries rather than removing the date of the missing entry

Reply
New Contributor
Posts: 2

Assigning a zero to blank entries rather than removing the date of the missing entry

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

Super User
Super User
Posts: 9,211

Re: Assigning a zero to blank entries rather than removing the date of the missing entry

Posted in reply to joshkylepearce

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;
New Contributor
Posts: 2

Re: Assigning a zero to blank entries rather than removing the date of the missing entry

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

Super User
Super User
Posts: 9,211

Re: Assigning a zero to blank entries rather than removing the date of the missing entry

Posted in reply to joshkylepearce

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

Super User
Posts: 13,046

Re: Assigning a zero to blank entries rather than removing the date of the missing entry

Posted in reply to joshkylepearce

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.

SAS Employee
Posts: 24

Re: Assigning a zero to blank entries rather than removing the date of the missing entry

[ Edited ]
Posted in reply to joshkylepearce

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;

 

Ask a Question
Discussion stats
  • 5 replies
  • 138 views
  • 0 likes
  • 4 in conversation