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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.