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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20
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.

Reeza
Super User

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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