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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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
  • 3 replies
  • 945 views
  • 1 like
  • 4 in conversation