SAS display date from TODAY() function - date

In SAS I want to reference the date in MMDDYY form but it keeps spitting out the crazy numbers and not in proper format at all!! I think it is doing the UNIX time.....
Here is what I have after importing the dates from an excel file:
date_today = today();
put date_today = mmddyy10.;
RUN;
PROC PRINT;
RUN;
What am I doing wrong>?! please help , thank you so much!!

Try this:
Data foo;
format date_today mmddyy10.;
date_today = today();
run;
proc print data=foo;
run;

Related

use a character date string as a date in data step

I have the following two macro variables:
%let start_date = 29MAY2014;
%let end_date = 15JUL2014;
I would like to create a dataset which is a series of dates between these (inclusive.) I cannot change the input format of the macro variables &start_date and &end_date.
I have tried many variations of the following, but SAS spits out an error for each:
data base_dates;
do date = put("&start_date",date9.) to put("&end_date",date9.);
output;
end;
format date date11.;
run;
Any help in this would be much appreciated
Use them as date literals, enclose in quotes and add a d at the end.
Do date = "&start_date"d to "&end_date"d;
It was simple; input() instead of put()
data base_dates;
do date = input("&start_date",date9.) to input("&end_date",date9.);
output;
end;
format date date11.;
run;

How To store SAS dates in a macro

I am trying to create different datasets with the names starting from a date which has data for different dates. When i am trying to run the code it is reading the date as numeric numbers and not as Dates. Here is the code
data dates;
input dates mmddyy8. name : $10. ;
format dates date9.;
cards;
01312015 swati
02282015 kangan
01232015 Gotam
04302015 Hushiyar
05172015 yash
09192015 Kuldeep
08302015 David
05172015 yash
11192015 Uninayal
11192015 Uninayal
12032015 sahil
;
data dates;
set dates;
format new date9.;
new=intnx('month', dates, 0, 'e');
run;
proc sql;
select distinct new into : new1 -: new8 from dates;
quit;
%put &new1.;
%macro swati;
%do i= 1 %to 1;
data data_&&new&i.;
set dates;
if new="&&new&i." then output data_&&new&i.;
run;
%end;
%mend;
%swati;
When I try running this code it gives me the error that says it is reading the dates stored in the macro as numbers. How do i make SAS read the dates as just dates only?

sas date format to read yyyymmdd

I have imported a dataset to SAS using Proc import. Now the problem is I can't change the date format in that dataset. In data the date is in YYYYMMDD for sales date, i wanted to change this is as 02Dec2005. Please find the data below. Please find the SAS code for import
DATA:
StoreID SalesDate InvoiceNumber ProductCode qty SalesType Brick
A0110515 20051205 225004 3519671 1 0 1638
proc import out=sample datafile="C:\Users\Vigneshwaran\Desktop\Vignesh\vipin1.txt"
dbms=tab replace;
getnames=yes;
datarow=2;
run;
Thanks and Regards,
V
You have to use a separate step. PROC IMPORT does not allow you to change formats.
PROC DATASETS can be used to change formats (among other things).
proc datasets lib=work nolist;
modify sample;
format SalesDate date9.;
run;
quit;
There can be 2 Solutions based on how your data was imported and what is the attribute of SalesDate column,
/* IF SalesDate is imported as Numeric */
proc datasets lib=work nolist;
modify sample;
format SalesDate date9.;
run;
/* IF SalesDate is imported as Character */
data want;
set sample(rename=(salesdate=sdate));
length SalesDate 8.;
format SalesDate date9.;
SalesDate=input(SDate,yymmdd8.);
drop SDate;
run;
Try this:
salesdate_1 = input(put(salesdate,10.),yymmdd10.);
and then add just your format date9.
I always work with this.
PROC DATASETS can be used to change formats. But PROC IMPORT is going to read 20051205 as an integer number. Interpreted as a DATE value, that would be 20,051,205 days after January 1, 1960. That's more than 20,000 years after 1960. December 5, 2005 is 16775 days after January 1, 1960. So you need to transform the numeric to character then back to numeric.
My suggestion would be to run the PROC IMPORT interactively and save the code. You can then modify the code, adding something like
SaleDate = INPUT(PUT(salesdate,8.),YYMMDD8.) ;
FORMAT SaleDate DATE9. ;
to convert the integer number into a SAS date. If modifying the code isn't possible, either run a data step with the above transformation, or PROC SQL with the same transformation after the IMPORT.
DATA final (RENAME=(saledate=salesdate));
SET sample ;
SaleDate = INPUT(PUT(salesdate,8.),YYMMDD8.) ;
FORMAT SaleDate DATE9. ;
DROP salesdate ;
RUN ;
or
PROC SQL STIMER EXEC ;
CREATE TABLE final AS
SELECT StoreID, INPUT(PUT(salesdate,8.),YYMMDD8.) AS SalesDate,
InvoiceNumber, ProductCode, qty, SalesType, Brick
FROM sample
;
QUIT ;
where the PROC SQL would be followed by DomPazz' PROC DATASETS to change the format to DATE9.

Import date from a txt SAS

Currently I'm trying to import a .txt file to SAS, but I have one problem. The .txt I recieve has a columnthat looks this way
.......;2015/09/01 09:49;....
I need to import it as a date value not as a string. I've tryed many formats but none of them works correctly.
data aux;
infile "&LIBIN/&fichero" delimiter = ';' MISSOVER DSD lrecl=32767;
format fecha_mov .... ;
informat fecha_mov ....;
input
fecha_mov ;
run;
Thanks for the help in advanced,
Antonio,
The informat anydtdtm. works for me.
https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002605552.htm
data want;
infile cards dsd dlm=',';
informat dt anydtdtm.;
format dt datetime21.;
input dt;
cards;
2015/09/01 09:49
2015/09/01 08:49
2015/09/02 09:49
2015/09/05 09:49
;
run;
proc print;
run;
I would suggest using a more specific informat- that way if the source file ever changes unexpectedly, you remove the risk of the anydtdtm. format interpreting it incorrectly. If you use the : format modifier, you can ignore the time part and just use yymmdd10.:
data want;
infile cards dsd dlm=',';
input dt :yymmdd10. another_var $5.;
format dt yymmdd10.;
cards;
2015/09/01 09:49,dummy
2015/09/01 08:49,dummy
2015/09/02 09:49,dummy
2015/09/05 09:49,dummy
;
run;
proc print;
run;
N.B. if you don't use a : then SAS will not move the line pointer to the next delimiter character before starting to read in the next variable.

convert numeric date into DATE in SAS Enterprise Guide

I have a date column which dates are showing as numeric, such as "201101", "201203"...
How can I convert these numeric date into format as "Jan2011", "Mar2012" by using SAS enterprise?
Thanks!
You can do it like this:
DATA test;
input date;
CARDS;
201101
201203
;
RUN;
data test2;
set test;
date2 = input(put(date,6.),yymmn6.);
format date2 monyy7.;
run;
Marti Mayo's answer is correct - but just wanted to point out that it only needs the one step:
DATA test;
format date monyy7. ; *<--- Sets the format you want to view (JAN2011) ;
input date :yymmn6.; *<--- Sets the informat of what you read in(201101);
CARDS;
201101
201203
;RUN;