BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SURIM
Obsidian | Level 7

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?

 

segmentcountdate
A200002019-09-30
B280002019-09-30
C140002019-09-30
D500002019-09-30
E40002019-09-30
A220002019-08-31
B270002019-08-31
C16002019-08-31
D480002019-08-31
E45002019-08-31

 

Release: 3.8 (Enterprise Edition)

 

BR

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Is date suppose to represent a timestamp here?

SURIM
Obsidian | Level 7

Yes! I need to create a new table that holds a timestamp (date) in order to follow up over time. 

PeterClemmensen
Tourmaline | Level 20

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
Obsidian | Level 7
Worked like a charm. Big thanks for this!
Tom
Super User Tom
Super User

@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.

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 1176 views
  • 0 likes
  • 3 in conversation