Reputation: 669
i need to update a dataset with the register of every modify of another dataset. I mean, with a proc append, sas has to add an observation (temp) to an existing dataset (register), that will contain the today's date and some values from another dataset (values).
ex of register
date VAL1 VAL2
2015-01-01 12 23
2015-01-02 22 14
example of temp
date VAL1 VAL2
2015-03-11 10 9
ex of register when done:
date VAL1 VAL2
2015-01-01 12 23
2015-01-02 22 14
2015-03-11 10 9
my try:
%macro mymacro;
data temp (keep DATE VAL1 VAL2);
set values;
date= datetime();
run;
proc append base=register data=temp; run;
%mend;
data register;
length var1 8. var2 8. date 8. ;
format date yymmdd.;
run;
%mymacro;
i have some problem with date-format, can you please help me? this is driving me crazy. have i got to define some lenght for register's var or for temp's var?
the result is a number in the var date, i expect a date, obviously
Upvotes: 0
Views: 576
Reputation: 4006
Use today() instead of datetime()
%macro mymacro;
data temp;
/*set values;*/
date= today();
/*keep DATE VAL1 VAL2;*/
run;
proc append base=register data=temp;
run;
%mend;
data register;
length var1 8. var2 8. date 8.;
format date IS8601DA10.;
run;
%mymacro;
also to keep the iso format you show in your examples, use
IS8601DA10.
Upvotes: 0
Reputation: 1710
You are probably looking for date()
or today()
rather than datetime()
which returns the current datetime rather than the current date.
It should not be necessary to create an empty register
data set in advance, as proc append
will do this for you.
You can then add the format statement to your temp
data step and the the format will be carried through:
data temp (keep date val1 val2);
format date yymmdd10.;
set values;
date = today();
run;
Upvotes: 0
Reputation: 2762
First, SAS has both dates and datetimes. Both of are represented by numbers, and the variables are numeric. Submit the following code and you'll see that March 11, 2015 is equal to 20158, the number of days since Jan 1, 1960. Today's datetime is equal to 1741677677 at the time I ran it; this is the number of seconds since the beginning of Jan 1, 1960.
data _null_;
d=date();
dt=datetime();
put d=;
put dt=;
run;
In SAS, you would represent these numbers with the appropriate formats. Applying a date format, such as date9.
to the date, tells SAS to print the date that corresponds to the number. Same thing with the datetime value:
data _null_;
d=date();
dt=datetime();
put d= date9.;
put dt= datetime.;
run;
In your case, it looks like you want to use the date()
function to return the date, rather than the datetime.
Upvotes: 2