DATA Step, Macro, Functions and more

date format

Accepted Solution Solved
Reply
Contributor
Posts: 46
Accepted Solution

date format

Hello all.I want to use qtr function but the date d that is shown in result is 01/01/1960 which is different from the date that i want as i put in my sas code.Any help is appreciated to correct my mistake.

 

data nn;
d = '05/19/2016' ;
p     = qtr   (d);
format  d  ddmmyy10. ;

run;


Accepted Solutions
Solution
‎01-26-2018 01:10 PM
Super User
Posts: 23,311

Re: date format

SAS date values need to be specified in DATE9 format which is ddMONYY such as 16May2016

And when specifying a date, you need to include a d after the quotation marks to indicate the difference between a date and just a plain string. 

 

Note that you can also just format your date as a quarter variable, I created a variable Z, which is identical to d but formatted as a quarter.

 

data nn;
d = "19May2016"d;
p     = qtr   (d);

z = d;
format  d  ddmmyy10.  z qtr.;
run;

View solution in original post


All Replies
PROC Star
Posts: 1,215

Re: date format

[ Edited ]
data nn;
   d='19may2016'd;
   p=qtr(d);
   format d ddmmyy10.;
run;

 QTR function requires a numeric variable, and in your code d is a character variable. Specify it as a date constant using the date9 format as "19may2016"d with the trailing d specifying that it is a date constant.

Super User
Posts: 9,914

Re: date format

You tried a wrong method for spelling out a SAS date literal. The correct method is this:

d = '19may2016'd;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
‎01-26-2018 01:10 PM
Super User
Posts: 23,311

Re: date format

SAS date values need to be specified in DATE9 format which is ddMONYY such as 16May2016

And when specifying a date, you need to include a d after the quotation marks to indicate the difference between a date and just a plain string. 

 

Note that you can also just format your date as a quarter variable, I created a variable Z, which is identical to d but formatted as a quarter.

 

data nn;
d = "19May2016"d;
p     = qtr   (d);

z = d;
format  d  ddmmyy10.  z qtr.;
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 147 views
  • 1 like
  • 4 in conversation