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;
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;
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.
You tried a wrong method for spelling out a SAS date literal. The correct method is this:
d = '19may2016'd;
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.