Hello,
I have a program that will run on the last day of every month to see how customer segments are changing over time. What I am trying to achieve is basically a timestamp since I don't have that anywhere in the data.
I need something like shown below. Every month I want the date the count and the segment group to be appended to the existing table. The segment and count I can do, but how do I put todays date as a date every month, just appending it to the existing data and not altering what is already in the table?
segment | count | date |
A | 20000 | 2019-09-30 |
B | 28000 | 2019-09-30 |
C | 14000 | 2019-09-30 |
D | 50000 | 2019-09-30 |
E | 4000 | 2019-09-30 |
A | 22000 | 2019-08-31 |
B | 27000 | 2019-08-31 |
C | 1600 | 2019-08-31 |
D | 48000 | 2019-08-31 |
E | 4500 | 2019-08-31 |
Release: 3.8 (Enterprise Edition)
BR
use PROC APPEND and do something like this
data have;
input segment $ count date :yymmdd10.;
format date yymmdd10.;
datalines;
A 20000 2019-09-30
B 28000 2019-09-30
C 14000 2019-09-30
D 50000 2019-09-30
E 4000 2019-09-30
A 22000 2019-08-31
B 27000 2019-08-31
C 1600 2019-08-31
D 48000 2019-08-31
E 4500 2019-08-31
;
/* Some data you create with todays timestamp */
data newdata;
segment='F';
count=10000;
date=today();
format date yymmdd10.;
run;
proc append base=have data=newdata;
run;
Is date suppose to represent a timestamp here?
Yes! I need to create a new table that holds a timestamp (date) in order to follow up over time.
use PROC APPEND and do something like this
data have;
input segment $ count date :yymmdd10.;
format date yymmdd10.;
datalines;
A 20000 2019-09-30
B 28000 2019-09-30
C 14000 2019-09-30
D 50000 2019-09-30
E 4000 2019-09-30
A 22000 2019-08-31
B 27000 2019-08-31
C 1600 2019-08-31
D 48000 2019-08-31
E 4500 2019-08-31
;
/* Some data you create with todays timestamp */
data newdata;
segment='F';
count=10000;
date=today();
format date yymmdd10.;
run;
proc append base=have data=newdata;
run;
@SURIM wrote:
Yes! I need to create a new table that holds a timestamp (date) in order to follow up over time.
Do you want to store a DATE value or a DATETIME (aka timestamp) value?
Dates are stored as a number of days and datetime values are stored as a number of seconds.
Doesn't make much difference in the overall approach in how to append an observation to a dataset, just in the details of what value to store.
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.